我有这段代码。试图将表单值从一个内部页面传递到另一个页面,但没有成功。
这是代码:
<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 -->
它基本上不起作用。。。没有错误,但也没有值。
您的操作应该是要处理post变量的php脚本,方法应该是post。
<form action="somefile.php" method="post">
错误很可能在这里:
<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>
<form action="post" name="myform">
是错误的。
应该是这样的:
<form method="post" name="myform" action="">
您需要发送一个POST方法。该操作为空,因此它将其发送到页面本身。
'action'
应该是作为目标URL的页面。你把method="post"
和action="post"
弄混了。将操作设置为"second_page.php".
我不完全理解您所说的内部页面是什么意思,但如果它是同一个页面,只是一个不同的div,那么将操作留空(action=''
)。