Alex Stone
Alex Stone

Reputation: 11

HTML Form not "Posting" user input values to PHP POST Arrary. I am trying to email a form

Seemingly simple issue: I have an HTML form:

<form action="submit.php" method="post" enctype="text/plain">

            <h3>Owner Information</h3>
            First Name*: <br />
            <input type="text" name="firstname" /><br />
            Last Name*: <br />
            <input type="text" name="lastname" /><br /><br />
            Are you the owner on title?*: <br />
            <input type="radio" name="titleowner" value="yes" />Yes
            <input type="radio" name="titleowner" value="no" />No<br /><br />
</form>

And then here is submit.php:

<?php

$admin_email = "[email protected]";
 $email = "[email protected]";
$subject = "subject";
$message = htmlspecialchars($_POST['firstname'] . " " . $_POST['lastname']);
$message .= "Title Owner? " . htmlspecialchars($_POST["titleowner"]);
$message .= "Mailing Address: " . htmlspecialchars($_POST['mailingaddress']) . "City: " .      htmlspecialchars($_POST['city']) . "State:" . htmlspecialchars($_POST['state']) . "Zip Code" .   (int)$_POST['zipcode'] . "Phone Number:" . strip_tags($_POST['phoneNum']);

//send email
mail($admin_email, $subject, $message);

echo $message;

//Email response
echo "Thank you for contacting us!";
?>

The 'echo message' produces this when the user submits:

Title Owner? Mailing Address: City: State:Zip Code0Phone Number:Thank you for contacting us!

As you can see, the variable for some reason did not populate. Any help is very much appreciated. Thank you.

Upvotes: 0

Views: 57

Answers (2)

sEver
sEver

Reputation: 2295

For POST forms you should use the enctype="multipart/form-data". Thats what I'm using for the email forms and it just works.

As Quentin stated in the comments though, the default for a form without file fields is enctype="application/x-www-form-urlencoded", so if you want to state an enctype explicite, use that one.

Upvotes: 0

Quentin
Quentin

Reputation: 943569

This:

enctype="text/plain"

is the culprit. The text/plain encoding isn't reliably machine decodable and PHP won't parse it.

Remove the enctype attribute entirely.

Upvotes: 2

Related Questions