Hi, I am working on a form where the date fields need to be required and i'd like to have verification that they are numbers. For some reason the first field will not validate, even when numbers are entered. It seems to get stuck there. Email verification is working just fine. Here is the code and a link to the site:
http://www.haepibean.com/sign_up1.phpCode:<?php $email_sent = false; $error_message = ""; if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "kate@madisonandmi.com"; $email_subject = "Contact Form Submission"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } function validate_form($email, $age_month, $age_day, $age_year) { // Validates Email Exists if(strlen($email) == 0) { return 'The Email Address is required.'; } // Validate Email is in the right format $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp, $email)) { return 'The Email Address you entered does not appear to be valid.'; } // Validate month is a number $number_exp = '/\d+/'; if(!preg_match($number_exp, $age_month)) { return 'Please enter the number of the month your child was born. ie. January = 01'; } // Validate day is a number $number_exp = '/\d+/'; if(!preg_match($number_exp, $age_day)) { return 'Please enter the day your child was born.'; } // Validate year is a number $number_exp = '/\d+/'; if(!preg_match($number_exp, $age_year)) { return 'Please enter the year your child was born. ie. 2007'; } } // Validation expected data exists if(!isset($_POST['email']) || !isset($_POST['age_month']) || !isset($_POST['age_day']) || !isset($_POST['age_year'])) { $error_message = 'We are sorry, but there appears to be a problem with the form you submitted.'; } $email = $_POST['email']; // required $age_years = $_POST['age_month']; // required $age_months = $_POST['age_day']; // required $age_months = $_POST['age_year']; // required $error_message = validate_form($email, $age_month, $age_day, $age_year); if(strlen($error_message) == 0) { // No errors, Send Email $body = "Form details below.\n\n"; $body .= "Email: ".clean_string($email)."\n"; $body .= "Month: ".clean_string($age_month)."\n"; $body .= "Day: ".clean_string($age_day)."\n"; $body .= "Year: ".clean_string($age_year)."\n"; // create email headers $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); $email_sent = @mail($email_to, $email_subject, $body, $headers); if (!$email_sent) { $error_message = "Failed sending email"; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="shortcut icon" href="http://www.haepibean.com/favicon.ico" type="image/x-icon"> <link rel="icon" href="http://www.haepibean.com/favicon.ico" type="image/x-icon"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Haepi Bean | Speech & Language Development Tools for Babies & Children | Ages 3 months - 5 Years</title> <meta name="description" content="Haepi Bean | Language & Speech Development Tools for Babies & Children | Ages 3 months - 5 Years" /> <meta name="keywords" content="expressive language disorder, latetalker, speech and language goals, language development in toddlers" /> <link href="style/style.css" rel="stylesheet" /> <meta property="og:title" content="Haepi Bean | Language & Speech Development Tools for Babies & Children | Ages 3 months - 5 Years" /> <meta property="og:type" content="website" /> <meta property="og:url" content="http://www.haepibean.com" /> <meta property="og:image" content="http://www.haepibean.com/images/hb-LOGO.png" /> <meta property="og:description" content="Haepi Bean is a subscription-based service that targets babies' and childrens' speech, language, and feeding milestones. Monthly packages are sent with games, toys, activities which facilitate the development of these milestones along with helpful tips and age-appropriate strategies to support speech and language development. " /> <meta property="og:site_name" content="Haepi Bean" /> <meta property="fb:admins" content="831950129" /> </head> <body> <?php include 'header.php'; ?> <div class="content"> <table width="950px"> <tr> <td style="padding:50px 60px 15px 60px"> <center> <span class="orange_head">We expect to begin offering subscription services in Mid-2014. </span> </center> <img src="images/joinus-pic.png" alt="speach development learning packages" align="left" style="margin-right:40px; margin-top:30px" /> <table cellpadding="15"> <tr> <td> <?php if(strlen($error_message) > 0) { ?> <div class="error_panel"> Oops! These errors appear below:<br /> <br /> <div class="error_message"><?php echo $error_message; ?></div> <br />Please fix these errors and <a href="http://www.haepibean.com/sign_up.php">try again</a>.<br /> <br /> </div> <?php } else if ($email_sent) { ?> <div class="success"> Thank you for your interest in Haepi Bean! <p>We will be in touch soon. </p><br /> </div> <?php } else { ?> <form name="dform" method="post" onsubmit="return formCheck(this);"> <p> <span class="purple">Leave your information, and you will be contacted<br /> once we are up and running!</span> </p> <p>email : <input type="text" name="email" style="width: 215px; height: 15px; overflow: hidden; background-color: #ffffff; border: solid; border-width: 1px; border-color: #6986B7; font-family: Arial, Helvetica, sans-serif; color: #6986B7; font-size: 14; letter-spacing: 1px;" /> </p><p> child’s birthday: <input type="text" name="age_month" maxlength="2" minlength="2" style="width: 20px; height: 15px; overflow: hidden; background-color: #ffffff; border: solid; border-width: 1px; border-color: #6986B7; font-family: Arial, Helvetica, sans-serif; color: #6986B7; font-size: 14; letter-spacing: 1px;" /> / <input type="text" name="age_day" maxlength="2" minlength="2" style="width: 20px; height: 15px; overflow: hidden; background-color: #ffffff; border: solid; border-width: 1px; border-color: #6986B7; font-family: Arial, Helvetica, sans-serif; color: #6986B7; font-size: 14; letter-spacing: 1px;" /> / <input type="text" name="age_year" maxlength="4" minlength="2" style="width: 40px; height: 15px; overflow: hidden; background-color: #ffffff; border: solid; border-width: 1px; border-color: #6986B7; font-family: Arial, Helvetica, sans-serif; color: #6986B7; font-size: 14; letter-spacing: 1px;" /> </p> <input type="image" src="images-splash/hb-learnmorebutton.png" value="submit" name="submit" style="border: none; background: #ffffff; margin-left: 0px;" /> </form> <?php } ?> </td></tr></table> <p><img src="images/excited_to_join.png" alt="we are excited for you to join the haepi bean family!" /> </p></center> </td> </tr> </table> </div> <?php include 'footer.php'; ?> </body> </html>
And help would be so appreciated!!
thanks!



Reply With Quote


Bookmarks