0

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.

hakre
200k55 gold badges454 silver badges868 bronze badges
asked May 16, 2012 at 9:45
2
  • How were you testing the variables to see if they were empty? Show your receiving PHP page. Commented May 16, 2012 at 9:50
  • Did you try removing the enctype from the <form> tag? Commented May 16, 2012 at 9:55

2 Answers 2

1

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">

answered May 16, 2012 at 9:56
Sign up to request clarification or add additional context in comments.

4 Comments

There is no <input type="file">
You are right, but this will work in any case, with or without file upload
Thanks, this worked. I wasn't aware that text/plain didn't allow the data to be used via the post method.
Or just leave no 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.
1

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.

answered May 16, 2012 at 9:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.