PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The form validation below, for one reason or another does not validate my form input, I don't understand where my mistake it, probably in the elseif, but i wasn't sure how I could demonstrate to check everything, besides maybe pipelines, or && but i wasn't sure.
<?php
if (empty($_POST['name'])) {
echo "Please fill out your name so we can give you credit for your lovely work";
} elseif(empty($_POST['sender_email'])) {
echo "please enter a valid email. Thank you";
} elseif(empty($_POST['title'])) {
echo "We need a title for your poem : )";
} elseif(empty($_POST['poem'])) {
echo "the idea is to submit a poem , that requires a poem, thank you!";
}
$email = $_POST['sender_email'];
if (!eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
{
echo "You've entered an invalid email format, please provide an email like yourname@yahoo.com, Thank you ";
}
?>
Despite my obvious problem to relate the question.
I am wondering why when the form is submitted, with mistakes I know I am making like, emails '3i3i3i3' or spaces omitted, yet, the form processes anyway, despite my logic telling it to warn the user, so as to allow for the proper information to be put in.
/**
* Tests if the input matches a the basic syntaxical rules of an email address
*
* @return bool
*/
static public function email($value)
{
return (bool)preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', trim($value));
}
I didn't know you could use if in continouslly, I appreciate the help; especially on the reg expression, cuz that <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> is over my head.