I have a pretty simple form in php but my problem is people can leave it blank and it still goes through when i hit submit I want to make the fields required and error messages to show when they dont. i have one working for email if something is entered in email it can be cecked to make sure is correct format but if its left blank it goes through hopefully somebody can help thanks Ger <?php $ip = $_POST['ip']; $qkemail = $_POST['qkemail']; $attn = $_POST['attn']; $qkname = $_POST['qkname']; $qkcitfr = $_POST['qkcitfr']; $qkcountryfr = $_POST['qkcountryfr']; $qkcitto = $_POST['qkcitto']; $qkcountryto = $_POST['qkcountryto']; $qkcube = $_POST['qkcube']; $qkmfdate = $_POST['qkmfdate']; $qkmfmonth = $_POST['qkmfmonth']; $qkmfyear = $_POST['qkmfyear']; if(!$qkemail == "" && (!strstr($qkemail,"@") || !strstr($qkemail,"."))) { echo "<h2>Use Back - Enter valid e-mail</h2>\n"; $badinput = "<h2>Feedback was NOT submitted</h2>\n"; echo $badinput; die ("Go back! ! "); } $todayis = date("l, F j, Y, g:i a") ; $attn = $attn ; $subject = $attn; $message = " $todayis [EST] \n Name: $qkname \n \n The Customer is moving from \n $qkcitfr \n $qkcountryfr \n \n The Customer is moving to \n $qkcitto \n $qkcountryto \n \n The customer is moving a total of $qkcube cubes on or around $qkmfdate/$qkmfmonth/$qkmfyear \n "; $from = "From: $qkemail\r\n"; mail("info@my domain.com", $subject, $message, $from); ?> <p align="center"> Date: <?php echo $todayis ?> <br /> Thank You : <?php echo $qkname ?> ( <?php echo $qkemail ?> ) <br /> We will be in touch shortly <br /><br /> <a href="index.html"> Next Page </a> </p> </body> </html>
You have to validate each field. Not only to see if it was filled out or not, but also so malicious data isn't submitted. Use preg_match with an if clause.
2 great functions - isset and preg_match ( both can be found on php.net ). Find them, learn them, add them = problem solved
Beware of isset though. A field with just a space entered will count as being "set", so you have to always use preg_match afterwards.