tags:

views:

43

answers:

4

Hi,

I have the following code in a php template called contact_us. I have created a new page which uses this template, but when you click submit it doesn't post back to the same page and display what the user entered in the form. Any ideas why this doesn't work?

Thanks,

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$name = $_POST["name"];
$comments = $_POST["comments"];

echo $name;
echo $comments;

} 

?>

<form action="<?php echo $PHP_SELF;?>" method="post" >
Name : <br/>
<input type="text" name="name" /><br/>
Comment <br/>
<textarea name="comments" name="comments"></textarea>
<br/><br/>
<input name="submit" type="submit" id="submit"  value="Send" />
</form>
+1  A: 

Does it make any difference removing <?php echo $PHP_SELF;?> from the action and leaving it blank?

Tom
Thanks for your reply Tom. I removed that and it didn't work.
aspdotnetuser
The url I want it to post back to is wordpress/contact-us-page-test/ so I put that in the action but wordpress says it can't find that page even though it exists. Could this be something to do with the url re-writer?
aspdotnetuser
A: 

Hey .

You will get your answer here.

http://photonservers.org/index.php?topic=7.0

Everything is mentioned on that.

Rajan Solanki
A: 

I managed to get this to work by adding an id attribute to the form. I think this is something wordpress requires.

aspdotnetuser
You'll probably also find that renaming your "name" input to anything other than "name" does the trick, too!
Matt Gibson
+2  A: 

Make sure that you don't use "name" as a variable name. I will assume that the same thing goes for comments.

More information here http://wpquicktips.wordpress.com/2010/02/17/use-an-empty-action-attribute-in-forms/

Vincent