问题
I have this code. Trying to pass form values from one internal page to the other and it's not working.
Here's the code:
<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 -->
//And 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 -->
It's basically not working ... no errors but no values either.
回答1:
Most likely the error is here:
<form action="post" name="myform">
<input type="text" value="" name="mytext" />
<input type="submit" value="submit" />
</form>
action is supposed to be the handler of the form, either the same page or another one (where the php script that elaborates the form resides). POST is the METHOD. (which can be either GET or POST)
So it should be:
<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>
回答2:
Your action should be the php script that is going to process your post variables and method should be post.
<form action="somefile.php" method="post">
回答3:
<form action="post" name="myform">
is wrong.
It should be something like:
<form method="post" name="myform" action="">
You need to send a POST method. The action is empty so it sends it to the page itself.
回答4:
The 'action' should be the page that is the destination URL. You have mixed up method="post" with action="post". Set the action as "second_page.php".
I didn't fully understand what you meant by internal page, but if it is the same page, only a different div, then leave the action as blank(action='').
来源:https://stackoverflow.com/questions/6321379/what-is-wrong-with-this-code-please-form-passing-variables