【发布时间】:2017-11-17 16:42:22
【问题描述】:
我有一个带有表单的页面 (index.html)。提交时,数据被发布到 php 文件中,然后将所述数据存储在(临时)xml 文件中,但是,我也有许多 iframe 也包含表单。
起初,我打算简单地将 iframe 中的输入数据发布到单独的 php 文件中,但遇到了几个问题:
-我有几个 iframe,但我没有固定数量,因为用户应该能够删除/添加 iframe。因此,我不能只告诉 iframe 1 将其数据发送到 php-file no。 1,iframe 2 将其数据发送到 php-file no.2 等..,我需要一个灵活的解决方案。
-我尝试将所有 iframe 输入提交到一个 php 文件,并希望它能够工作,因为这个 php 文件将数据发送到的 xml 文件只是更新而不是完全覆盖。正如您可能猜到的那样,这不起作用。
-我遇到的另一个问题是用户可能会返回并编辑他在 iframe 中输入的任何内容。只有在他单击 html 文件中的保存按钮后才能保存数据以防止这种情况发生。
我也尝试过通过 JavaScript 提交数据,正如有类似问题的人所建议的那样,但这对我来说并不奏效。所以我想我想要的是一个关于我应该如何去做的建议。单击“主”保存按钮后,如何发送所有数据,数据是否进入多个 php 文件并不重要。解决方案不应依赖于固定数量的元素,因为数量并不总是相同。
这是 iframe-html:
<form method="POST" action="php/iframe.php">
<label>Your thoughts:</label>
<input type="text" name="header">
<label>Suggestions:</label>
<textarea type="text" name="textbox"></textarea>
<input type="button" value="submit">
</form>
(对于所有 Iframe 来说基本相同)。 如果您需要任何其他信息,请告诉我。 编辑:我读到同时提交表格可能会造成干扰,我知道很多
编辑:
相关index.html:
<form method="post" action="main.php">
<div id="firstSection"
<label>First input</label>
<input type="text" name="input[]">
<button type="button" onclick="openIframe1()">Read more</button>
</div>
<div id="secondSection"
<label>Second input</label>
<input type="text" name="input[]">
<button type="button" onclick="openIframe2()">Read more</button>
</div>
<button type="submit" value="submit"></button>
</form>
<div class="iframe">
<button type="button" class="close">Close</button>
<iframe src="iframe1.html"></iframe>
</div>
<div class="iframe">
<button type="button" class="close">Close</button>
<iframe src="iframe2.html"></iframe>
</div>
【问题讨论】:
-
为什么有 iFrame。您可以添加带有表单输入的 DIVS 并拥有一个提交按钮。如果您需要提交多个表单,则不能不使用 JavaScript。 “但这对我没有用。”不是有用的评论
-
我没有编写 html 代码,我会看看是否可以更改它,我正在关注这篇文章 stackoverflow.com/questions/7843355/… 的答案,但我没有提交它们,可能是因为我试图将它们发送到同一个 php 文件,但我在我的问题中详细说明了这一点
-
如果您显示minimal reproducible example,我们可以为您提供更好的帮助
-
您希望看到什么代码?为了保持最小化但完整,我需要知道
-
1.插入/删除 iframe 的脚本。 2. 足够的 html 来显示问题。点击
<>创建一个sn-p假设插入都是客户端