问题描述
|
我有这个代码。试图将表单值从一个内部页面传递到另一内部页面,但它不起作用。
这是代码:
<div data-role=\"page\" id=\"home\">
<div data-role=\"header\">
<h1>Page One</h1>
</div><!-- /header -->
<div data-role=\"content\">
<form action=\"post\" name=\"myform\">
<input type=\"text\" value=\"\" name=\"mytext\" />
<input type=\"submit\" value=\"submit\" />
</form>
</div><!-- /content -->
</div><!-- /page -->
//第2页
<div data-role=\"page\" id=\"page2\">
<div data-role=\"header\">
<h1>Page Two</h1>
</div><!-- /header -->
<div data-role=\"content\">
<?PHP if (isset($_POST[\'mytext\'])) {
// do something with $_POST[\'value\']
echo \'it works\'; } ?>
</div><!-- /content -->
</div><!-- /page -->
它基本上不起作用...没有错误,但也没有值。
解决方法
错误最有可能在这里:
<form action=\"post\" name=\"myform\">
<input type=\"text\" value=\"\" name=\"mytext\" />
<input type=\"submit\" value=\"submit\" />
</form>
action应该是表单的处理程序,可以是同一页面,也可以是另一页面(详细说明表单的php脚本所在的位置)。 POST是方法。 (可以是GET或POST)
因此应该是:
<form action=\"\" method=\"POST\" name=\"myform\"> <!-- action = \"\" reloads the same page,otherwise you could write action=\"myphppage.php\" or whatever -->
<input type=\"text\" value=\"\" name=\"mytext\" />
<input type=\"submit\" value=\"submit\" />
</form>
, 您的操作应该是将要处理post变量的php脚本,并且方法应该是post。
<form action=\"somefile.php\" method=\"post\">
, <form action=\"post\" name=\"myform\">
是错的。
应该是这样的:
<form method=\"post\" name=\"myform\" action=\"\">
您需要发送POST方法。该操作为空,因此将其发送到页面本身。
, \'action\'
应该是作为目标URL的页面。您已将method=\"post\"
和action=\"post\"
混合在一起。将动作设置为“ 10”
我不完全了解您所说的内部页面是什么意思,但是如果它是同一页面,则只有一个不同的div,然后将操作保留为空白(action=\'\'
)。