开发者

Is it possible to include a form in a wordpress page?

开发者 https://www.devze.com 2023-01-15 11:39 出处:网络
I have the following code in a php template called contact_us. I have create开发者_C百科d a new page which uses this template, but when you click submit it doesn\'t post back to the same page and disp

I have the following code in a php template called contact_us. I have create开发者_C百科d 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>


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/


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号