2012-03-09 259 views
0

我的用戶可以輸入多個地址,但我想要一個實際的按鈕來生成額外的字段,因爲只有一個地址是強制性的,空字段看起來很醜!我也需要額外的地址進入mysql數據庫。 我會怎麼做的JavaScript如果PHP是不可能 一些代碼,可以幫助:向PHP表單添加更多字段(用戶可以添加多個地址)

<td width="732" valign="top"><p> 
<h3 class="main">Address Details</h3> 
<p class="normal"> You are able to add up to 3 addresses but only 1 is compulsory. 
However it would be helpful if you could insert 3 addresses: 
<ul> 
<li>Permanent home address</li> 
<li>Postal address (where you will be from June to September)</li> 
<li>Local address (where you currently live)</li> 
</ul>  
<?php 
if(!empty($err)) { 
    echo "<div class=\"msg\">"; 
    foreach ($err as $e) { 
    echo "* $e <br>"; 
    } 
    echo "</div>";  
    } 
?> 
<br> 
<form action="address.php" method="post" name="regForm" id="regForm" > 
<table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms"> 
<tr> 
<td>Street<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Street" type="text" id="Street" class="required" size="50"> 
</tr> 
<tr> 
<td>Line 2 
</td> 
<td><input name="Line2" type="text" id="Line2" class="required" size="50"> 
</tr> 
<tr> 
<td>Line 3 
</td> 
<td><input name="Line3" type="text" id="Line3" class="required" size="50"> 
</tr> 
<tr> 
<td>Town<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Town" type="text" id="Town" class="required" size="30"> 
</tr> 
<tr> 
<td>Postcode<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Postcode" type="text" id="Postcode" class="required" size="10"> 
</tr> 
<tr> 
<td>Country <font color="#CC0000">*</font></span></td> 
<td><select name="Country" class="required" id="select8"> 
      <option value="" selected></option> 
      <option value="Afghanistan">Afghanistan</option> 
      <option value="Albania">Albania</option> 
      (etc) 
      </select></td> 
</tr> 
<tr> 
<td>Telephone Number<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Tele" type="text" id="Tele" class="required" > 
</tr> 
<tr> 
<td>Fax<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Fax" type="text" id="Fax" class="required" > 
</tr> 
<tr> 
<td>Mobile<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Mobile" type="text" id="Mobile" class="required" > 
</tr> 
<tr> 
<td>Type <font color="#CC0000">*</font></span></td> 
<td><select name="Type" class="required" id="select8"> 
      <option value="" selected></option> 
      <option value="H">Home</option> 
      <option value="P">Postal</option> 
      <option value="L">Local</option> 


</table> 
<p align="center"> 
<input name="doAddress" type="submit" id="doAddress" value="Submit"> 

回答

2

解決您解析錯誤 - 把;在行$numrows = 0 + $_GET['numrows']

生成多個字段的結束動態 - 使用JavaScript,真的,這是更好的這個任務比PHP

+0

你能幫我的javascript請 – user1257518 2012-03-09 17:20:38

+0

檢查http://stackoverflow.com/questions/2145012/adding-rows-dynamically-with-jquery和http: //stackoverflow.com/questions/171027/add-table-row-in-jquery。這些示例使用jQuery - 它很容易學習,您在實現任務時不應該有任何問題 – maialithar 2012-03-09 18:05:53

相關問題