我想要做的是在表单下面放两个按钮。一个验证它(必填字段)然后提交。另一个验证的是(再次需要字段),然后添加额外的表单(用于附加地址),但事实是,每次单击第二个按钮时,它应该添加表单。
我只需要使用HTML和PHP。
我的HTML:
form id="form" method="post">
Адрес ред 1 <span class="alert"> * <?php echo $address_line_1Err ?></span> <input type="text" name="address_line_1" /><br>
Адрес ред 2 <input type="text" name="addres_line_2" /><br>
Пощенски код <span class="alert"> * <?php echo $address_zipErr ?></span> <input type="text" name="address_zip" /><br>
Населено място <span class="alert"> * <?php echo $address_cityErr ?></span> <input type="text" name="address_city" /><br>
Област <span class="alert"> * <?php echo $address_provinceErr ?></span> <input type="text" name="address_province" /><br>
Държава <input type="text" name="address_country" /><br><br>
<span class="alert"> * Полетата са задължителни </span><br><br><br><br>
<input class="submit1" id="submit1" type="submit" value="Стъпка 3" name="submit" >
<input type="submit" id="add" name="add" value="Допълнителен адрес" />
我的PHP:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(empty($_POST["address_line_1"])) {
$address_line_1Err = "Адрес е задължителен";
}
if(empty($_POST["address_zip"])) {
$address_zipErr = "Пощенски код е задължителен";
}
if(empty($_POST["address_city"])) {
$address_cityErr = "Населено място е задължително";
}
if(empty($_POST["address_province"])) {
$address_provinceErr = "Област е задължителна";
} else {
header('Location: step3.php');
}}
答案 0 :(得分:0)
请尝试以下操作。在提交按钮之前添加以下代码: -
if(isset($_POST["add"])){
Адрес ред 1 <span class="alert"> * <?php echo $address_line_1Err ?></span> <input type="text" name="address_line_1" /><br>
Адрес ред 2 <input type="text" name="addres_line_2" /><br>
Пощенски код <span class="alert"> * <?php echo $address_zipErr ?></span> <input type="text" name="address_zip" /><br>
Населено място <span class="alert"> * <?php echo $address_cityErr ?></span> <input type="text" name="address_city" /><br>
Област <span class="alert"> * <?php echo $address_provinceErr ?></span> <input type="text" name="address_province" /><br>
Държава <input type="text" name="address_country" /><br><br>
}