regoch Posted July 30, 2011 Share Posted July 30, 2011 Hello! I got this script for online contact form. When i got all field filled it's send mail and show page normally. but when i don't fill all fields it's show what field it's not filled but not continue with rest of site, don't show right column (podaci_desno) or footer (dno_unutra). I try remove die(); after errors but no help from that. Any ideas? <!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" lang="en" xml:lang="en"> <head> <title>Plivački klub Zadar</title> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="author" content="Fer Projekt, Put Murvice 14, Zadar, 099/212-9600" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="/css/pk-zadar.css" type="text/css" charset="utf-8" /> <link rel="stylesheet" href="/css/fontovi.css" type="text/css" charset="utf-8" /> <script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript" src="/js/banners.min.js"></script> <script type="text/javascript" src="/js/jQueryEqualHeight.js"></script> </head> <body> <div id="pozadina_unutra"> <div id="sadrzaj_unutra"> <div id="meni_unutra"> <table id="Table_01" style="width:991px;height:138px;" border="0" cellpadding="0" cellspacing="0"> <tr> <td rowspan="2"> <img src="/images/menu_unutra_01.png" width="1" height="138" alt="PK Zadar" /></td> <td rowspan="2"> <a href="/"> <img src="/images/menu_unutra_02.png" width="310" height="138" border="0" alt="PK Zadar" /></a></td> <td rowspan="2"> <img src="/images/menu_unutra_03.png" width="77" height="138" alt="PK Zadar" /></td> <td> <a href="/"> <img src="/images/menu_unutra_04.png" onmouseover="this.src='/images/menu_unutra_04a.png'" onmouseout="this.src='/images/menu_unutra_04.png'" width="90" height="99" border="0" alt="PK Zadar" /></a></td> <td> <a href="/o-klubu"> <img src="/images/menu_unutra_05.png" onmouseover="this.src='/images/menu_unutra_05a.png'" onmouseout="this.src='/images/menu_unutra_05.png'" width="83" height="99" border="0" alt="PK Zadar" /></a></td> <td> <a href="/natjecanja"> <img src="/images/menu_unutra_06.png" onmouseover="this.src='/images/menu_unutra_06a.png'" onmouseout="this.src='/images/menu_unutra_06.png'" width="98" height="99" border="0" alt="PK Zadar" /></a></td> <td> <a href="/novost"> <img src="/images/menu_unutra_07.png" onmouseover="this.src='/images/menu_unutra_07a.png'" onmouseout="this.src='/images/menu_unutra_07.png'" width="85" height="99" border="0" alt="PK Zadar" /></a></td> <td> <a href="/galerije"> <img src="/images/menu_unutra_08.png" onmouseover="this.src='/images/menu_unutra_08a.png'" onmouseout="this.src='/images/menu_unutra_08.png'" width="81" height="99" border="0" alt="PK Zadar" /></a></td> <td> <a href="/treneri"> <img src="/images/menu_unutra_09.png" onmouseover="this.src='/images/menu_unutra_09a.png'" onmouseout="this.src='/images/menu_unutra_09.png'" width="74" height="99" border="0" alt="PK Zadar" /></a></td> <td> <a href="/kontakt"> <img src="/images/menu_unutra_10a.png" onmouseover="this.src='/images/menu_unutra_10a.png'" onmouseout="this.src='/images/menu_unutra_10a.png'" width="92" height="99" border="0" alt="PK Zadar" /></a></td> </tr> <tr> <td colspan="7"> <img src="/images/menu_unutra_11.png" width="603" height="39" alt="PK Zadar" /></td> </tr> </table> </div><!-- Kraj menu index --> <div id="podaci_livo"> <span class="naslov">Kontakt</span><br /><br /> Adresa:<br /> Plivački klub ZADAR<br /> Kolovare bb<br /> 23000 ZADAR<br /><br /> Telefon: <br /> +385 (23) 312-320<br /><br /> E-mail adrese: <br /> [email protected]<br /> [email protected]<br /> [email protected]<br /> [email protected]<br /><br /> Radno vrijeme u kojem nas možete kontaktirati osobno ili telefonom je:<br /> Radnim danom:<br /> od 8,00 - 11,00 sati i od 17,00 - 19,00 sati <br /> Subotom:<br /> od 9,00 - 11,00 sati <br /><br /> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> <form name="contactform" method="post" action=""> <table width="450px"> </tr> <tr> <td valign="top"> <label for="first_name">First Name *</label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top""> <label for="last_name">Last Name *</label> </td> <td valign="top"> <input type="text" name="last_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="email">Email Address *</label> </td> <td valign="top"> <input type="text" name="email" maxlength="80" size="30"> </td> </tr> <tr> <td valign="top"> <label for="telephone">Telephone Number</label> </td> <td valign="top"> <input type="text" name="telephone" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="comments">Comments *</label> </td> <td valign="top"> <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"> </td> </tr> </table> </form> <br /><br /> </div><!-- Kraj podaci_livo --> <div id="podaci_desno"> <?php include("include/desno_box.php")?> </div><!-- Kraj podaci_desno --> <div class="clear" /> </div><!-- Kraj sadrzaj_unutra --> </div><!-- Kraj pozadina_unutra --> <div id="dno_unutra"> <?php include("include/dno_box.php")?> </div><!-- Kraj dno_unutra --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/243288-online-contact-form-error/ Share on other sites More sharing options...
joel24 Posted July 31, 2011 Share Posted July 31, 2011 you should separate the functions from the code, and it's the die(); function being called in your 'died()' function which is stopping the rest of the page from showing... try somethign like this <?php function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Your email subject line"; $error = false; // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { $error_message = 'We are sorry, but there appears to be a problem with the form you submitted.'; $error=true; } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = (isset($error_message))?$error_message:''; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; $error=true; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; $error=true; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; $error=true; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; $error=true; } #check that errors weren't set if($error) { $email_message = "Form details below.\n\n"; $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); echo 'Thank you for contacting us. We will be in touch with you very soon.'; } } Quote Link to comment https://forums.phpfreaks.com/topic/243288-online-contact-form-error/#findComment-1249618 Share on other sites More sharing options...
IrOnMaSk Posted August 3, 2011 Share Posted August 3, 2011 the whole point of the form is that users fill them in and go to the next page... but if you want to proceed to proceed anyway (kinda pointless) you can do away the funtion died() function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } and the validation if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } Quote Link to comment https://forums.phpfreaks.com/topic/243288-online-contact-form-error/#findComment-1251513 Share on other sites More sharing options...
regoch Posted August 4, 2011 Author Share Posted August 4, 2011 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/243288-online-contact-form-error/#findComment-1251857 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.