I was given this form by a designer who built it in html and I need to create some php to process the form. However, when I tested the form to see if it would pass variables, $_POST was empty. When, however, I changed the method to get, I could access the variables fine. Can anyone see where the error is?
Here is the code:
<form action="process/appointment.php" method="post" accept-charset="utf-8" enctype="text/plain" id="appointments">
<input type="text" placeholder="Contact Name..." name="contactName" style="width:150px;"/>
<input type="text" placeholder="Contact Telephone..." name="contactTel" style="width:150px;"/>
<!--<input type="image" src="images/send_purple.gif" alt="send appointment request" style="margin-top:0; height:auto; border:none;"/>-->
<input type="submit" value="submit">
</form>
EDIT
Here is the page I was using to test the receipt of the variables:
<?php
print_r($_POST); print_r($_GET);
?>
$_POST returns an empty array when the form is set to post, but $_GET returns the values when the for is set to get.
2 Answers 2
Your enctype is wrong, you need enctype="multipart/form-data"
Swap this line :
<form action="process/appointment.php" method="post" accept-charset="utf-8" enctype="text/plain" id="appointments">
to
<form action="process/appointment.php" method="post" accept-charset="utf-8" enctype="multipart/form-data" id="appointments">
4 Comments
<input type="file">enctype, which will default to enctype="aplication/x-www-form-urlencoded", which is a smaller transfer than multipart/form-data, and just as easily processed by PHP.enctype="text/plain" doesn't make much sense. Remove it.
If it is doing anything at all, it is telling the browser to encode the data in a way that PHP can't convert to $_POST.
enctypefrom the<form>tag?