在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>
答案 0 :(得分:1)
这不起作用,因为您的代码目前包含一个包含在另一个表单中的表单。这不允许嵌套表单。
您当前的代码:
<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
。
当您提交此新表单时,它将:
$_POST