Jump to content

Recommended Posts

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);
 

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']) ]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.