Jump to content

error code - 2 more opening braces than expected


Oscar11

Recommended Posts

I am new to php.  Please advise me where I am going wrong.

 

<?php

if ($_POST ['formsubmit']  == 'submit')

          {

// EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "xxxxxxxxxxxx";

    $email_subject = "Enquiry Form";

 

          function died($error) {

Did the code get cut off? Or are you just wondering about the errors caused by the missing closing brackets?

 

<?php
if ($_POST ['formsubmit']  == 'submit') {
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "xxxxxxxxxxxx";
    $email_subject = "Enquiry Form";
 
    function died($error) {
    }
}
?>

Have tidied up form and found some missing parenthese.  Form seems to be working but i do want to highlight the fields that don't get filled in.  How do I do this please?

 

 

php

if ($_POST ['formsubmit']  == 'submit')

          {

// EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "xxxxxxxxx";

    $email_subject = "Enquiry Form";

          function died($error) {

         

// your error code can go here

        echo "We're sorry, but there were errors found with the form you submitted.<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']) ||

          if (!isset($_POST['last_name']) ||

         if (!isset($_POST['home_address']) ||

        if (!isset($_POST['post_code']) ||

if (!isset($_POST['is_the_student_resident_at_this_address']) ||

        if (!isset($_POST['email']) ||

        if (!isset($_POST['mobile_number']) ||

        if (!isset($_POST['students_first_name']) ||

        if (!isset($_POST['students_last_name']) ||

        if (!isset($_POST['subject_required']) ||

        if (!isset($_POST['level_of_subject']) ||

        if (!isset($_POST['nature_of_help_required'])) {

        if (!isset($_POST['able_to_travel']) ||

                   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

    $home_address = $_POST['home_address']; // required

    $post_code = $_POST['post_code']; // required

  $is_the_student_resident_at_this_address =       $_POST['is_the_student_resident_at_this_address']; // required

    $email_from = $_POST['email']; // required

    $mobile_number = $_POST['mobile_number']; // required

    $students_first_name = $_POST['$students_first_name']; // required

    $students_last_name = $_POST['$students_last_name']; // required

    $subject_required = $_POST['subject_required']; // required

    $level_of_subject = $_POST['level_of_subject']; // required

    $nature_of_help_required = $_POST['nature_of_help_required']; // required

     $able_to_travel = $_POST['able_to_travel']; // required

         

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

header( "Location: http://www.tfeethowsthis.webspace.virginmedia.com/thankyou.html" );

}

else

{

         

$body = " From: $title_field\n\n Your_first_name: $your_first_name_field\n\n Your_second_name: $your_second_name_field\n\n Your_home_address: $your_home_address_field\n\n Post_code: $post_code_field\n\n Email: $email_field\n\n $landline_number\n\n Mobile_phone: $mobile_phone_field\n\n Subject_required: $subject_required_field\n\n Level_of_study: $level_of_study_field\n\n Name_of_school: $name_of_school_field\n\n Nature_of_help: $nature_of_help_required_field\n\Able_to_travel: n $able_to_travel_field\n\n ";

?>

By "highlight the fields", do you mean that you don't those fields (the ones which haven't been completed) included in the email? If so, you can use isset():

<?php
//...
 
$body  = " From: $title_field\n\n Your_first_name: $your_first_name_field";
if(isset($your_second_name_field)) { $body .= "\n\n Your_second_name: $your_second_name_field"; }
$body .= "\n\n Your_home_address: $your_home_address_field\n\n Post_code: $post_code_field\n\n Email: $email_field\n\n $landline_number\n\n Mobile_phone: $mobile_phone_field\n\n Subject_required: $subject_required_field\n\n Level_of_study: $level_of_study_field\n\n Name_of_school: $name_of_school_field\n\n Nature_of_help: $nature_of_help_required_field\n\Able_to_travel: n $able_to_travel_field\n\n ";
?>
 
 
Also, when posting code to the forum in the future, please surround the code with

tags. It makes the code and your post easier to follow.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.