简体   繁体   English

如何通过php文件将文本数据从表单获取到iframe?

[英]How to get text data from form to iframe via php file?

So I have a form: 所以我有一个表格:

<fieldset>
<legend>Post a comment:</legend>


<form target="forum" method="post" action="forum.php">    

//Targeting the iframe in my form (`<form target="forum"`) & Submitting the form to my PHP file (`action="forum.php"`) 

                Name: <br />
        <input type="text" name="fname" /><br />
                Subject:<br />
        <input type="text" name="subject" size="50"/><br />
                Comment:<br />
<textarea name="comment" rows="10" cols="100">Hello,</textarea><br />
<input type="submit" value="Send" />
<input type="reset" value="Reset" />
</fieldset>
</form>

Then I want to take the text data (name, subject and comment) and put that into an iframe on the click of a button <input type="submit" value="Send" /> ... 然后,我想获取文本数据 (名称,主题和注释), 然后单击按钮 <input type="submit" value="Send" />将其放入iframe中

The iframe is on the same page as the form (below it) and looks like this... iframe与表单位于同一页面 (在其下方),看起来像这样...

<iframe name="forum" src="forum.php" 
width="900" height="500" ></iframe>

Once the text data has been inputted I wanted the iframe to store that data there permanently. 输入文本数据后,我希望iframe将数据永久存储在那里。 Basically like a forum within an iframe. 基本上就像是iframe中的论坛。

How do I process the form in the php file and spit out the result into the iframe? 如何处理php文件中的表格并将结果吐到iframe中?

make the source of the iframe forum.php and include the parameters in the URL ? 制作iframe forum.php的源并将URL中包含参数? use $_GET in PHP to get the parameters ? 在PHP中使用$ _GET获取参数?

<iframe id="myiframe" src="forum.php?fname=blah&subject=blah"></iframe>

So you would use javascript to change the src of the iFrame on the submit of the form : 因此,您可以使用javascript更改提交表单时iFrame的src:

document.getElementById['myiframe'].src = "forum.php?fname=blah&subject=blah";

then in PHP get the variables and do what you need todo with them to produce the desired output: 然后在PHP中获取变量并执行所需的操作以产生所需的输出:

$fname = $_GET['fname'];
$subject = $_GET['subject'];
// do some processing

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

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