Form validation
Posted: Wed Aug 23, 2006 1:49 am
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.
Code: Select all
<?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 ";
}
?>Code: Select all
<form action="send_simpleform.php" name="msgform" method="POST">
<p><b>your name</b>
<input type="text" name="name" size="30"></p>
<p><b>your email</b>
<input type="text" name="sender_email" size="30"></p>
<p><b>your title</b>
<input type="text" name="title" size="30"></p>
<p><b>your poem</b>
<TEXTAREA NAME="poem" COLS="30" ROWS="5" WRAP="virtual"></TEXTAREA></P>
<p><input type="submit" name="submit" value="send your poem!"></p>