在联系表格中上传表格,上传表格提交会不断提交整个表格 [英] upload form within a contact form, the upload form submit keeps submitting the whole form

查看:83
本文介绍了在联系表格中上传表格,上传表格提交会不断提交整个表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在php联系表单中有一个上传和提交按钮,但是在单击提交以进行文件上传时,此提交按钮将提交整个表单,主提交按钮也将提交整个表单。因此,用户无法上传文件。我如何确定文件提交没有提交整个表单?

Got an upload and submit button within a php contact form, but upon clicking submit for file upload, this submit button submits the whole form, and so does the main submit button. Hence the user cannot upload a file. how can i make sure the file submit does not submit the whole form?

<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> 


推荐答案

这不起作用,因为您的代码当前包含一个表格包含在另一表格中。

This doesn't work because your code currently contains a form enclosed into another form. This is not allowed to nest forms.

您当前的代码:

<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 contactform.php

You must also move the PHP code from upload_ac.php to contactform.php.

提交此新表单时,它将:

When you submit this new form, it will:


  • 上传所选文件

  • 填充 $ _ POST 字段的值

  • upload the file you selected
  • populate $_POST with the values of the fields

这篇关于在联系表格中上传表格,上传表格提交会不断提交整个表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆