Oscar11 Posted January 20, 2014 Share Posted January 20, 2014 My code isn't working and I have put it into notepad++ and using a php error checker. I want to put the code on here for help but know that you like it presented in a certain way to make life easier for all concerend. How do I indent the code properly on here? Ideally I don't want the form submitted unless certain fields are filled in. A pop up box which says please fill in your ...... . <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "xxxxx@xxxxxxx"; $email_subject = "Your email subject line"; function died($error) {{// Does this field have a value? if (empty($_REQUEST[$fieldName])) { echo 'Please go back and fill out ' . $fieldName . "<br>\n";// validation expected data exists if(empty($_POST['first_name']) || empty($_POST['last_name']) || empty($_POST['email']) || empty($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } if ((!first_name) || (!second_name)) { $errorMsg = 'Please make sure you have filled in the required fields:<br /><br />'; if (!$first_name) { $errorMsg = 'Please fill in your First Name<br />'; } if (!$seond_name) { $errorMsg = 'Please fill in your Second Name<br />'; } if (!$mobile_number) { $errorMsg = 'Please fill in your contact number<br />'; } if (!$email) { $errorMsg = 'Please fill in your email address<br />'; } } //strip lashes $first_name = stripslashes($name); $second_name = stripslashes($second_name); $phone = stripslashes($phone); $email = stripslashes($email);//clean 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); Quote Link to comment Share on other sites More sharing options...
dalecosp Posted January 20, 2014 Share Posted January 20, 2014 //code goes in code tags [php] $mycode; [/php] Quote Link to comment Share on other sites More sharing options...
JIXO Posted January 20, 2014 Share Posted January 20, 2014 Where are you defining dead function ? try this, it may work : <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "xxxxx@xxxxxxx"; $email_subject = "Your email subject line"; // function died($error) { --> What is this doing here //{ // Does this field have a value? if (empty($_REQUEST[$fieldName])) { echo 'Please go back and fill out ' . $fieldName . "<br>\n"; // validation expected data exists if(empty($_POST['first_name']) || empty($_POST['last_name']) || empty($_POST['email']) || empty($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } if ((!first_name) || (!second_name)) { $errorMsg = 'Please make sure you have filled in the required fields:<br /><br />'; } // --> You forgot a closing the if statement if (!$first_name) { $errorMsg = 'Please fill in your First Name<br />'; } if (!$seond_name) { $errorMsg = 'Please fill in your Second Name<br />'; } if (!$mobile_number) { $errorMsg = 'Please fill in your contact number<br />'; } if (!$email) { $errorMsg = 'Please fill in your email address<br />'; } } //strip lashes $first_name = stripslashes($name); $second_name = stripslashes($second_name); $phone = stripslashes($phone); $email = stripslashes($email); //clean 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); } // --> Also forgot to close the if [ isset($_POST['email']) ] Quote Link to comment 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.