Click to See Complete Forum and Search --> : Form Submission Problem please help
Serik
09-01-2006, 03:41 PM
Ok here is the form I have.. www.mellonhosting.com/art/registration.zip
I am really new to PHP
how can I make it so if any of these fields are left blank it will not allow the submission
and also I would like to get the errors from the fields being left blank to appear next to the required field
chesemonkyloma
09-01-2006, 04:10 PM
Try searching "form validation" on google, theres thousands of tutorials on this.
Phill Pafford
09-01-2006, 05:01 PM
You could use JavaScript to validate, or use something like this.
See my other thread:Other Thread (http://www.webdeveloper.com/forum/showthread.php?t=119437)
bokeh
09-01-2006, 05:11 PM
You could use JavaScript to validateThat is true from the point of view of enhancing the user experience but whatever you do on the client you still must do as much serverside validation as you think would be necessary if it were the only form of validation.
Serik
09-01-2006, 06:19 PM
i cant use client side validation .... its to easy to get around...
i almost have it...
www.mellonhosting.com/art/enter.zip
but with the
$clear its stopping the submit when fields are left blank but it also seems to be stopping even when its filled out and when i take
if($_POST['submit_button'] && $clear==true) to
if($_POST['submit_button'] && $clear=true) it allows the submission even if fields arent filled....
sitehatchery
09-01-2006, 06:51 PM
Here's one fun way of doing it:
if($_POST['submit_button']){
switch(true){
case empty($_POST['name']):
case empty($_POST['email']):
case empty($_POST['blabla']):
die('You did not fill in all the required fields.');
}
}
sitehatchery
09-01-2006, 07:12 PM
Ok, I guess that didn't work as expected. It only works if you leave the bottom fields blank. but here's a fix that will work. Probably overkill, but it was fun...
if($_POST['submit']){
switch(true){
case empty($_POST['name']):
if(empty($_POST['name']))$e[0]='name';
case empty($_POST['pass']):
if(empty($_POST['pass']))$e[1]='password';
echo 'You did not enter the following fields:<br>';
foreach($e as $key=>$val){
if($val!="") echo $val.<br>;
}
break;
default: echo 'Some success message, possibly.';
}
}