thuitamaina Posted February 15, 2016 Share Posted February 15, 2016 ...If you visit my website (www.thuitamaina.com) and click the contact link on the menu, a lightbox pop-up form appears. The problems arising are these:1) The pop-up lightbox that appears after pressing the submit buttton still shows you made a mistake in the contact details even if you filled all the info, put the right email address format and inserted the correct number of bananas in the captcha 2) The same mistake you made is mentioned several times after clicking submit button3) If you insert the right details, the "thank you" message is loaded on a different page instead of that same lightbox, and that's after a while. So I ask: 1)how do I make the mistake you made in contact details mentioned only once in the second lightbox? 2)how do I make only the "thank you" message (displayed after you insert correct details) appear in the second lightbox without loading another window?Please let me know how I can solve those problems. Below is the concerned php code: <?php $errors = ''; $myemail = 'thuitamaina@thuitamaina.com';//<-----Put Your email address here. if(empty($_POST['yourname']) || empty($_POST['email_address']) || empty($_POST['Message']) || empty($_POST['captcha'])) { $errors .= "\n Error: all fields are required"; echo '<br>' . $errors . '<br>'; } $yourname = $_POST['yourname']; $email_address = $_POST['email_address']; $Message = $_POST['Message']; $captcha = $_POST['captcha']; if (!preg_match( "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address)) { $errors .= "\n Error: Invalid email address"; echo '<br>' . $errors . '<br>'; } if ( $captcha != 2) { $errors .= "\n You inserted the wrong number of <b>FULL</b> bananas. You are not a genuine person!"; echo '<br>' . $errors . '<br>'; } if( empty($errors)) { // Include database connection settings include('clinton.php'); $yourname = $_POST['yourname']; $email_address = $_POST['email_address']; $Message = $_POST['Message']; mysql_query("INSERT INTO `thuitam_myDatabase`.`Contact_info` ( `Index` , `Name` , `Email` , `Message` ) VALUES ( NULL, '$yourname', '$email_address','$Message') "); //close connection mysql_close(); $to = $myemail; $email_subject = "Contact form submission: $yourname"; $email_body = "You have received a new message. ". " Here are the details:\n Name: $yourname \n ". "Email: $email_address\n Message \n $Message"; $headers = "From: $myemail\n"; $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); //Say 'thank you' //echo '<br>' . $errors . '<br>'; echo '<p>Hi ' . $yourname . '!</p> <p>Thank you for contacting me. I will try my best to get back to you as soon as possible. In case I delay in responding, feel free to call me via phone. My number is +254725-509941.</p> <p>Wishing You Every Joy,</p> <p>Thuita J. Maina.</> '; } Quote Link to comment https://forums.phpfreaks.com/topic/300820-how-do-i-solve-this-php-code-problem/ Share on other sites More sharing options...
ginerjm Posted February 15, 2016 Share Posted February 15, 2016 Your post begins with what looks like a conversation you are having with someone else. What are you trying to say to US? Your code is weak. You are collecting error messages but outputting them individually so if you have multiple errors you will see the messages multiple times. Either save the output of the errors until the end or do an exit once you do output a message. Your query looks like it has an error in it with that period in the middle of it. I don't know what else you have a problem with. Quote Link to comment https://forums.phpfreaks.com/topic/300820-how-do-i-solve-this-php-code-problem/#findComment-1531148 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.