简体   繁体   English

GET表单中的PHP POST表单

[英]PHP POST form inside a GET form

How can I make this possible? 我怎样才能做到这一点?

A POST form inside a GET form GET表单内的POST表单

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: 首先,我在3文本框中输入数据,然后按GET Submit按钮,然后按POST提交按钮,它就像GET一样,不显示if语句显示的数据:

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! 预先感谢你们!

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. 当然,将JS移出HTML会更好,但是,正如我所说的,这只是为了展示原则上可以做到这一点。

As @cdhowie rightly noticed, you can't have form element inside another form element; 作为@cdhowie正确地注意到,你不能有form另一内部元素form元素; 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. 浏览器如何解释这种结构,这取决于它们(也许内部form只是作为无效元素而被忽略),但是绝对不允许您同时输入属于两种形式的结构。

A <form> element may not have other <form> elements as descendants, according to the HTML specification. 根据HTML规范, <form>元素可能没有其他<form>元素作为后代。 (See this related question .) (请参阅此相关问题 。)

Therefore, what you have here is invalid HTML. 因此,这里的内容是无效的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. 浏览器之间的行为可能不一致。

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. Facebook like button是一个很好的例子,您不能将其放在表单中,否则可能会破坏某些内容。

This isn't the normal procedure.. This is not possible. 这不是正常过程。这是不可能的。 I think, you want to have both the effects from GET and POST. 我想,您希望同时具有GET和POST的作用。 Maybe you can do it with some nasty tricks, add them to the end of the url with Javascript. 也许您可以使用一些讨厌的技巧来做到这一点,然后使用Javascript将其添加到url的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM