Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Submit is not Sending POST to php file

I am having trouble getting my javascript hyperlink button to post data to my php form email script. I have tried doing it several different ways, but nothing seems to work. Any help is appreciated. Thank you.

My form code:

<form id="form" action="contactform.php" method="POST" enctype="text/plain" >
      <fieldset>
        <label><strong>Your Name:</strong><input id="name" type="text" name="name">       </label>
        <label><strong>Your Phone Number:</strong><input id="phone" type="text" name="phone"></label>
        <label><strong>Your E-mail:</strong><input id="email" type="text" name="email"></label>
        <label><strong>Your Message:</strong><textarea id="message" name="message"></textarea></label>
        <div class="btns"><a href="contacts.html" class="button">Clear</a><a href="#" onclick="document.getElementById('form').submit();" class="button">Send</a></div>
      </fieldset>  
    </form>

Contactform.php:

<?php

    var_dump($_POST);

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


    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];


    $email_from = '[email protected]';
    $email_subject = "Contact Form Submission";
    $email_body = "Name: $name\n" . "Phone: $phone\n" . "Messge: $message";


    $to= '[email protected]';
    $headers= "From: $email_from \r\n";
    $headers.= "Reply-To: $visitor_email \r\n";
    mail($to,$email_subject,$email_body,$headers);

    echo "Thank you for your interest. I will contact you shortly.";

    }else{
    echo "It didn't work.";
    }


    ?>

Also, I have the var_dump at the beginning of the php for debugging purposes only. Not going to be a part of the final code.

like image 657
mtrussell Avatar asked Dec 27 '22 06:12

mtrussell


1 Answers

Remove enctype="text/plain" from the form tag, PHP doesn't support it.

See: method="post" enctype="text/plain" are not compatible?

like image 181
Sam Avatar answered Jan 05 '23 01:01

Sam