Reputation: 254
How can I make this possible?
A POST form inside a GET form
first I enter a data on the 3 textbox and press the GET submit button, then when I press the POST submit button it just acts like a GET and not displaying the data from what my if statement stated:
if(isset($_POST['post'])){
echo $_POST['data1']."<br/>".$_POST['data2']."<br/>".$_POST['data3'];
}
Please help me on this.. I really need this
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<?php
if(isset($_POST['post'])){
echo $_POST['data1']."<br/>".$_POST['data2']."<br/>".$_POST['data3'];
}
?>
<form action="" method="get">
<form action="" method="post">
<input type="text" name="data1" value="<?php if(isset($_GET['data1'])) echo $_GET['data1']; ?>"/>
<input type="text" name="data2" value="<?php if(isset($_GET['data2'])) echo $_GET['data2']; ?>"/>
<input type="text" name="data3" value="<?php if(isset($_GET['data3'])) echo $_GET['data3']; ?>"/>
<input type="submit" name="get" value="GET"/>
<input type="submit" name="post" value="POST"/>
</form>
</form>
</body>
</html>
thank you in advance guys!
Upvotes: 0
Views: 1855
Reputation:
You can't have a form inside another form. Facebook like button is a good example, You can't put it inside a form or you could break something.
Upvotes: 1
Reputation: 106385
Well, here's the proof of concept:
<form>
<input name="t" />
<input type="submit" value="with GET" />
<input type="submit" value="with POST"
onclick="this.parentNode.method='POST';"/>
</form>
Of course, it's quite better to move JS out of HTML, but, as I said, it's just to show how it can be done in principle.
As @cdhowie rightly noticed, you can't have form
element inside another form
element; how browsers will interpret this structure, it's up to them (perhaps the inner form
will just be ignored as an invalid element), but it definitely won't allow you to make your inputs belong to two forms at the same time.
Upvotes: 2
Reputation: 604
This isn't the normal procedure.. This is not possible. I think, you want to have both the effects from GET and POST. Maybe you can do it with some nasty tricks, add them to the end of the url with Javascript.
Upvotes: 0
Reputation: 169018
A <form>
element may not have other <form>
elements as descendants, according to the HTML specification. (See this related question.)
Therefore, what you have here is invalid HTML. The browser may do whatever it thinks is reasonable in this situation, including refusing to render the page at all. Behavior between browsers may not be consistent.
Upvotes: 1