2013-01-24 129 views
0

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

回答

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

當您提交這種新形式,它會:

  • 上傳您選擇
  • 填充$_POST與字段的值的文件