如何将 iframe id/name 发送到 php 文件


How to send iframe id/name to a php file?

我有一个带有名称的iframe,在本例中是一个从用户更改的电子邮件地址。我需要处理这个变量:

<iframe name="asd@asd.lol" src="index.html">

index.html 是一个简单的数据形式,如下所示:

<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="submit" value="Upload">
</form>

我需要将值"asd@asd.lol"传递给"upload.php"文件。这可能吗?

是否可以将

查询字符串参数添加到index.html文件中?

所以:

<iframe name="asd@asd.lol" src="index.html?email=asd@asd.lol">

然后在 index.html 文件中设置一个隐藏变量:

<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="hidden" name="email" id="email" value="">
<input type="submit" value="Upload">
</form>

如果这是一个纯HTML文件,你可以用一些javascript设置隐藏字段的值。

然后使用 $_POST["电子邮件"] 从隐藏字段中获取电子邮件值。

<form ENCTYPE="multipart/form-data" action="upload.php" method="POST" onsubmit='$(this).append('<input type="hidden" name="iframeEmail" value="'+$("iframe[src='index.html']").attr('name')+'">')'>
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="submit" value="Upload">
</form>

试试这个,如果它不起作用,那么放置iFrame和ID,并在jQuery选择器上找到它