我有一个表单
<form name="frm_passport" id="frm_passport" action="" method="POST">
<input name="ws[surname]" id="surname" type="text" value="<?php echo (isset($_POST['ws']['surname']) && $_POST['ws']['surname'] != '') ? $_POST['ws']['surname'] : ''; ?>"/>
<input name="ws[firstname]" id="firstname" type="text" value="<?php echo (isset($_POST['ws']['firstname']) && $_POST['ws']['firstname'] != '') ? $_POST['ws']['firstname'] : ''; ?>"/>
<input name="ws[prevname]" id="prevname" type="text" value="<?php echo (isset($_POST['ws']['prevname']) && $_POST['ws']['prevname'] != '') ? $_POST['ws']['prevname'] : ''; ?>"/>
这是我在表单提交后的代码
<?php
if (isset($_POST['Submit']) && $_POST['Submit'] != '') {
$_POST['ws']['surname'] = (isset($_POST['ws']['surname']) && $_POST['ws']['surname']!="")?$_POST['ws']['surname']:'';
$_POST['ws']['firstname'] = (isset($_POST['ws']['firstname']) && $_POST['ws']['firstname']!="")?$_POST['ws']['firstname']:'';
$_POST['ws']['prevname'] = (isset($_POST['ws']['prevname']) && $_POST['ws']['prevname']!="")?$_POST['ws']['prevname']:'';
echo $_POST['ws'];
}
?>
在上面的代码中,echo返回一个数组。
如何在提交以下表单时获得与$_POST['ws']
相同的数组格式。也就是说,我想在提交时获得数组中的所有表单字段。
<form name="frm_passport" id="frm_passport" action="" method="POST">
<input name="surname" id="surname" type="text" />
<input name="firstname" id="firstname" type="text"/>
<input name="prevname" id="prevname" type="text"/>
<input type="submit" name="Submit" value="Submit" id="Submit" />
</form>
我对数组了解不多。我是PHP的新手。请任何人帮帮我。提前感谢
您需要更改输入字段的名称,如下所示
<form name="frm_passport" id="frm_passport" action="" method="POST">
<input name="ws[surname]" id="surname" type="text" />
<input name="ws[firstname]" id="firstname" type="text"/>
<input name="ws[prevname]" id="prevname" type="text"/>
<input type="submit" name="Submit" value="Submit" id="Submit" />
</form>