Hi. Do you guys know what is the normal way of validation a form through php. I need the basic method of doing that.
Supposed I have a form with name, last name, email, address etc... If the user doesn't enter his/her name at all i want something in red to be written next to the address or whatever field doesn't contain anything.
Moreover the actual form sends data to some other php file.
Thanks!
php validation
Moderator: General Moderators
there is probably a better way to do this, but your script can always catch the empty field using the empty() function and throw the error back to the form.
script:
and in form.php where you want to display the error put:
you could do this check for all your fields but would result in alot of code. i tend to just have one check for all the fields and return a general error.
script:
Code: Select all
$firstName = $_POST['firstName'];
if(empty($firstName)){
header ("location: form.php?emptyfield=firstName");
exit;
}Code: Select all
if(isset($_GET['emptyfield']) && $_GET['emptyfield'] == "firstName"){
//output error!
}