PDA

View Full Version : Trouble Requiring Fields to be Complete


tsguitar2004
11-21-2004, 02:44 AM
Using two forms I found online (this one (http://www.phpfreakz.com/library.php?sid=156) and this one (http://www.apptools.com/phptools/forms/forms5.php)), I'm getting close to building what I need.

I need to add the ability to require that certain fields of the form are filled out before sending the form (without javascript).

I need to, sometime later, allow for those filling out the form to send more than one file.

And, of course, I need to be sure that a "mallicious user" won't take advantage of some gap I've left in posting this form.

I've tried to put some code in both forms, but I really don't know where to put it. The Apptools site had a pretty good (short) tutorial that had me thinking I understand what's what. But when I tried to make specific fields required, I had trouble. They mention adding error checking, but I can't make that happen with the knowledge I have right now!

Thanks for your help. Cheers.
-ts

IronCode
11-21-2004, 03:13 AM
<form name='myForm'>
<input type='text' name='field_one'>
<input type='submit' name='submit'>
</form>


ther is your form lol. by default all forms submit to themselves. so at the top of that enter something like the following.


<?php
if($_POST){
if(strlen($_POST['field_one'])>0){
// do your stuff because the field isn't empty.
}else{
echo "Wrong, try again with data this time.";
}
}
?>
<form name='myForm'>
<input type='text' name='field_one'>
<input type='submit' name='submit'>
</form>


that will check to make sure there is info in the field before exicuting anything else. if there isn't something there then they get the message to enter something.

schotte
11-21-2004, 11:50 AM
Instead of

if(strlen($_POST['field_one'])>0){

you can also use:

if(!empty($_POST['field_one'])){

Frank

tsguitar2004
11-22-2004, 09:00 AM
Ok. I appreciate your advice. I'll get coding on it soon and post back. Thanks!
-ts