在一个表单中,我想为拥有长地址的人提供两个地址字段,但我不知道该怎么做 这是我的表单的样子:
<?php
# other..code
if isset($_POST['email']) {
$postinfo = http_build_query(
array(
'lname' => $lname,
'fname' => $fname,
'email' => $email,
'address' => $address,
'list' => $list,
'boolean' => 'true'
)
);
}
# other..code
?>
<div><label for="fname">First Name</label><input type="text" name="fname" id="fname"/></div>
<div><label for="lname">Last Name</label><input type="text" name="lname" id="lname"/></div>
<div><label for="email">Email</label><input type="text" name="email" id="email"/></div>
<div><label for="address">Address</label><input type="text" name="address" id="address"/></div>
所以我想要的是有两个单独的地址字段:
<div><label for="address">Address 1</label><input type="text" name="address" id="address"/></div>
<div><label for="address">Address 2</label><input type="text" name="address" id="address"/></div>
答案 0 :(得分:0)
您可以使用如下的输入数组。
<input type="text" name="address['longAddress]" id="address"/>
<input type="text" name="address['shortAddress]" id="address"/>
然后在php中访问它们。
echo $_POST['address']['longAddress'];
echo $_POST['address']['shortAddress'];
答案 1 :(得分:0)
您的数组(假设$address2
为$_POST['address2']
array(
'lname' => $lname,
'fname' => $fname,
'email' => $email,
'address' => $address . (!empty($address2) ? " ".$address2 : ''),
'list' => $list,
'boolean' => 'true'
)
HTML:
<div><label for="address2">Address 2</label><input type="text" name="address2" id="addres2s"/></div>
答案 2 :(得分:0)
两种可能的方法:
<div><label for="address-1">Address 1</label><input type="text" name="address-1" id="address-1"/></div>
<div><label for="address">Address 2</label><input type="text" name="address-2" id="address-2"/></div>
<div><label for="address">Address</label><textarea name="address" id="address"></div>