【问题标题】:Adding more field to PHP form (user can add more than one address)向 PHP 表单添加更多字段(用户可以添加多个地址)
【发布时间】:2012-03-09 16:46:32
【问题描述】:

我的用户可以输入多个地址,但我想要一个生成额外字段的实际按钮,因为只有一个地址是强制性的,空字段看起来很难看!我还需要额外的地址才能进入 mysql 数据库。 如果无法使用 PHP,我将如何使用 Javascript 一些可能有帮助的代码:

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

【问题讨论】:

    标签: php javascript mysql


    【解决方案1】:

    修复您的解析错误 - 将 ; 放在行尾 $numrows = 0 + $_GET['numrows']

    动态生成更多字段 - 使用 javascript,真的,它比 php 更适合这个任务

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 2015-06-11
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多