简体   繁体   English

如何从表单获取数据并将其发布到iframe?

[英]How to get data from a form and post it into iframe?

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

<fieldset>
<legend>Post a comment:</legend>
<form target="forum" method="post" action="forum.**SomeKindOfExtension**" >
                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 data (name, subject and comment) and put that into an iframe ... 然后,我想获取数据 (名称,主题和注释) 并将其放入iframe中 ...

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

Hopefully you can see my problem, which is what type of file will read the form data and display it in the iframe window ? 希望您能看到我的问题, 哪种类型的文件读取表单数据并将其显示在iframe窗口中 When I've been looking up answers people seem to be using javascript or php but I can't seem to make any of the code work for me. 当我一直在寻找答案时,人们似乎正在使用javascript或php,但我似乎无法使任何代码对我有用。

So if anyone could help me here that would be much appreciated. 因此,如果有人可以在这里帮助我,将不胜感激。

Using a iframe on the same page would make no sense because when you click on the submit button the whole page will be submitted to a different page specified it the action attribute of the form. 在同一页面上使用iframe毫无意义,因为当您单击“提交”按钮时,整个页面将被提交到指定表单的action属性的其他页面。

Instead you could use a different button (not the submit button) to send data to the iframe or use a parent page and then include your two frames ie the form and the iframe. 相反,您可以使用其他按钮(而不是“提交”按钮)将数据发送到iframe或使用父页面,然后包含两个框架,即表单和iframe。

Here's the first example 这是第一个例子

mainpage.html mainpage.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <BODY>

          <iframe src="frame.html" width="100%" height="100%" name="someFrame"></iframe>

          <FORM name="form1">
               <INPUT type="button" value="Click Me" 
               onClick="someFrame.document.form1.text1.value='Me!'">
          </FORM>
     </BODY>
</HTML>

frame.html frame.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <BODY>
          <FORM name="form1">
               <INPUT type="text" name="text1" size="25" value="">
          </FORM>
      </BODY>
</HTML>

Here's the second example 这是第二个例子

parent.html parent.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <FRAMESET cols="80%,20%">
          <FRAME SRC="left.html" name="left_frame">
          <FRAME SRC="right.html" name="right_frame">
     </FRAMESET>
</HTML>

left.html left.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <BODY>
          <FORM>
               <INPUT type="button" value="Click ME" 
               onClick="parent.right_frame.document.form1.text1.value='Me!'">
          </FORM>
     </BODY>
</HTML>

right.html right.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <BODY>
          <FORM name="form1">
               <INPUT type="text" name="text1" size="25" value="">
          </FORM>
      </BODY>
</HTML>

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

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