在联系表单中上传表单,上传表单提交会持续提交整个表单

2024-02-11

在 PHP 联系表单中有一个上传和提交按钮,但是单击“提交”进行文件上传后,此提交按钮将提交整个表单,主提交按钮也是如此。因此用户无法上传文件。我如何确保文件提交不会提交整个表单?

<table width="500" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>



<tr>
<td>
<!-- start here-->


<form action="contactform.php" method="post"> 
<table class="freecontact2form" border="0" width="400px">
<tbody>
<tr>
<td colspan="2"><span style="font-size: x-small;"> </span> <br /> <br /></td>
</tr>

<tr>
<td>Question 1<br>
  <br></td>
</tr>

<tr>
 <td><br>

   Answer 1 <input type="radio" name="ans" value="ans1" /><br />
  Answer 2 <input type="radio" name="ans" value="ans2"  /><br />
  Answer 3 <input type="radio" name="ans" value="ans3"  /><br />
  Answer 4 <input type="radio" name="ans" value="ans4"  /><br />

 </td> 
  </tr>

</tr>

<!--upload form Start here-->


<form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" >
<tr>
<td><strong>Upload form/strong></td>

</tr>

<tr>
<td>Below is for file upload:<br>
  <br></td>
</tr>

<tr>
<td>Select file
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>



<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</form>

<!--upload formend here-->





<tr>
<td style="text-align:center" colspan="2"><br /><br /> <input src="submit1.png" name="submit" type="image"> <br /><br /> 


 <br /><br /></td>
</tr>
</tbody>
</table>
</form>


<!-- end here -->

</td>
</tr>

</table>
</td>

</tr>
</table> 

这不起作用,因为您的代码当前包含一个包含在另一个表单中的表单。这是不允许嵌套表单的。

您当前的代码:

<form action="contactform.php" method="post"> 
...
<form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
...
</form>
...
</form>

试试这个代码:

<form action="contactform.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
Here you must add all the fields of the two previous forms.
</form>

您还必须将 PHP 代码从upload_ac.php to contactform.php.

当您提交此新表格时,它将:

  • 上传您选择的文件
  • 填充$_POST与字段的值
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在联系表单中上传表单,上传表单提交会持续提交整个表单 的相关文章

  • 如何制作骨头形状的纽扣

    我目前正在为我的网站试验一个按钮 我希望它看起来像一个普通按钮 但是一旦你将其悬停 它就会变成一根骨头 我的网站是关于狗的 所以我使用了一个已经存在的 codepen 项目 最终得到了这个 root bg 1a1e24 color eee
  • 使用 jQuery 重复元素

    我确信这对于正确的人来说是显而易见的 但是如何使用 jQuery 重复一个元素呢 本质上 我希望 jQuery 无限次重复内联元素 就像您使用 CSS 来重复背景纹理的图形一样 我一直在研究 clone 和 each 但确实可以使用一些指针
  • AngularJS:指令隔离范围 - 范围变量未定义

    请有人能给我解释一下为什么吗attrDir的范围变量是可见的 并且oneWay不是吗 我以为scope 也是孤立的 angular module test angular module test directive attrDir attr
  • 访问项目资源中的图像?

    如何在运行时访问已添加到项目资源中的图像 我希望能够做这样的事情 if value picBox1 image Resources imageA else picBox2 image Resources imageB Something I
  • MongoDB toArray 性能

    我正在尝试从 Mongo Node 中的术语集合构建类别树 但首先我使用 in 选择所有树元素 console time termsCol find var terms await termsCol find term id in flat
  • gitlab API有速率限制吗

    github对OAuth客户端的速率限制为5000 小时 但我找不到相同的信息gitlab 除了创建新用户和重置密码6次 分钟 是否意味着没有限制 答案是不再是 不 https gitlab com gitlab org gitlab ru

随机推荐