PHP form is not capturing message due to unkown validation error

JGallardo

My form is not sending the message because of an unexpected error, i cannot see what that error is. It just shows up in a red box and nothing happens to the form. I have looked over the code many times, at first it was looking for the php form in the wrong directory. But now I am stuck.

Website: http://proverbs.io/

Here is my code

The contact section is included through an include.

index.php

<?php include 'includes/contact.php';?>

contact.php

<section class="cta text-center">

  <div class="container">

    <div class="row">
      <div class="col-lg-12">
        <h2>Have a suggestion? <span class="highlight">We appreciate feedback!</span></h2>
        <p><button class="btn contact-button" type="button" role="button">Contact us</button></p>
        <div class='contact-form'>

          <form action="php/mail.php" method="POST" role="form">>
            <div class='name'>
              <input class='form-control first' placeholder='First Name' type='text' autofocus
              data-validation-type="string" id="form-name" placeholder="Full Name" name="name">
              <input class='last' placeholder='Last Name' type='text' name="last_name">
            </div>
            <div class='contact'>
              <input class='form-control email' placeholder='E-mail Address' type='text' id="form-email" name="email">
            </div>
            <div class='message'>
              <textarea class="form-control" placeholder='Your message' id="form-message" name="message" maxlength="999" style="resize:none"></textarea>
            </div>
            <div id="success"></div> <!-- For success/fail messages -->
            <footer class="submit-button">
              <button type="submit">Submit</button>
            </footer>
          </form>

        </div>
      </div>
    </div>

  </div>

</section>   

mail.php

<?php

    $email_to = "[email protected]";
    $email_from = "[email protected]";
    $email_subject = "Contact Form submitted";

    if(isset($_POST['email']))
    {

        function return_error($error)
        {
            echo $error;
            die();
        }

        // check for empty required fields
        if (!isset($_POST['name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['message']))
        {
            return_error('incomplete');
        }

        // form field values
        $name = $_POST['name']; // required
        $email = $_POST['email']; // required
        $message = $_POST['message']; // required

        // form validation
        $error_message = "Something went wrong. Just email [email protected]";

        // name
        $name_exp = "/^[a-z0-9 .\-]+$/i";
        if (!preg_match($name_exp,$name))
        {
            $this_error = 'Please enter a valid name.';
            $error_message .= ($error_message == "") ? $this_error : "<br/>".$this_error;
        }        

        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
        if (!preg_match($email_exp,$email))
        {
            $this_error = 'Please enter a valid email address.';
            $error_message .= ($error_message == "") ? $this_error : "<br/>".$this_error;
        } 

        // if there are validation errors
        if(strlen($error_message) > 0)
        {
            return_error($error_message);
        }

        // prepare email 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 .= "Name: ".clean_string($name)."\n";
        $email_message .= "Last Name: ".clean_string($last_name)."\n";
        $email_message .= "Email: ".clean_string($email)."\n";
        $email_message .= "Message: ".clean_string($message)."\n";

        // create email headers
        $headers = 'From: '.$email_from."\r\n".
        'Reply-To: '.$email."\r\n" .
        'X-Mailer: PHP/' . phpversion();
        if (mail($email_to, $email_subject, $email_message, $headers))
        {
            echo 'success';
        }
        else 
        {
            echo 'error';
            die();        
        }
    }
    else
    {
        echo 'incomplete';
        die();
    }
    ?>
Josh J

This is what happens when I fill out your form and hit submit.

Erros from console

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Display form validation error message on same page using only PHP?

From Dev

error message in jquery form validation

From Dev

Form validation - Error Message not output

From Dev

PHP Validation error message order

From Dev

AngularJS custom form validation error message

From Dev

Given error message is not displayed in Spring Form validation

From Dev

Form validation with error message using angular ngMessage

From Dev

AngularJS custom form validation error message

From Dev

Form validation error message is not shown in ModelForm

From Dev

Given error message is not displayed in Spring Form validation

From Dev

angularJs Form validation with dynamic error message

From Dev

Error message not working in simple javascript form validation

From Dev

php form validation and error messages

From Dev

php form validation message appearing twice

From Dev

Php login has error for some unkown reason

From Dev

Error message not displayed in php form

From Dev

multiple form validation error message in single alert message javascript

From Dev

Error message show before the form submit in angularjs form validation

From Dev

Error message show before the form submit in angularjs form validation

From Dev

Capturing client side validation message in selenium (testng)

From Dev

Contact form phone number validation error PHP

From Dev

How to give custom field name in laravel form validation error message

From Dev

html5 validation error message without submitting form

From Dev

How to make a JavaScript form validation that displays an error message simultaneously

From Dev

Symfony Validation Error Message for Missing Required Form Field

From Dev

AngularJS form validation: show error message for checkbox after click on submit

From Dev

Form validation display same error message for all fields

From Dev

PHP Form Login - Send Error Message

From Dev

unable to get form_validation->set_rules and form_validation->set_message error

Related Related

  1. 1

    Display form validation error message on same page using only PHP?

  2. 2

    error message in jquery form validation

  3. 3

    Form validation - Error Message not output

  4. 4

    PHP Validation error message order

  5. 5

    AngularJS custom form validation error message

  6. 6

    Given error message is not displayed in Spring Form validation

  7. 7

    Form validation with error message using angular ngMessage

  8. 8

    AngularJS custom form validation error message

  9. 9

    Form validation error message is not shown in ModelForm

  10. 10

    Given error message is not displayed in Spring Form validation

  11. 11

    angularJs Form validation with dynamic error message

  12. 12

    Error message not working in simple javascript form validation

  13. 13

    php form validation and error messages

  14. 14

    php form validation message appearing twice

  15. 15

    Php login has error for some unkown reason

  16. 16

    Error message not displayed in php form

  17. 17

    multiple form validation error message in single alert message javascript

  18. 18

    Error message show before the form submit in angularjs form validation

  19. 19

    Error message show before the form submit in angularjs form validation

  20. 20

    Capturing client side validation message in selenium (testng)

  21. 21

    Contact form phone number validation error PHP

  22. 22

    How to give custom field name in laravel form validation error message

  23. 23

    html5 validation error message without submitting form

  24. 24

    How to make a JavaScript form validation that displays an error message simultaneously

  25. 25

    Symfony Validation Error Message for Missing Required Form Field

  26. 26

    AngularJS form validation: show error message for checkbox after click on submit

  27. 27

    Form validation display same error message for all fields

  28. 28

    PHP Form Login - Send Error Message

  29. 29

    unable to get form_validation->set_rules and form_validation->set_message error

HotTag

Archive