我根据以下内容在codeigniter框架中发送了数组:
for (var i=1; i<=selected; i++) {
<div style="float: left; padding-left: 13px; padding-right: 12px; padding-top: 7px; margin-top: 0px;">'+i+'
</div>
<input type="text" name="unitName[]" id="unitName'+i+'" style="width:189px;" required />
<input type="text" name="ownerName[]" id="ownerName'+i+'" style="width:241px;" />
<input type="text" name="salutation[]" id="salutation'+i+'" style="width:137px;" /><br />
}
当我尝试使用以下内容发布它时:
$ownerNames = $this->input->post('ownerName');
if (is_array($ownerNames)) {
foreach( $ownerNames as $ownerName ) {
echo "Owner Name is : " . $ownerName;
}
} else {echo "Owner is not array";}
这是我的整个控制器,所有帖子:
if ($this->form_validation->run() == FALSE) {
$this->load->view('newblock');
} else {
$registrarName = $this->input->post('registrarName');
$blockName = $this->input->post('blockName');
$serviceType = $this->input->post('serviceType');
$number = $this->input->post('number');
$email = $this->input->post('email');
$address1 = $this->input->post('address1');
$address2 = $this->input->post('address2');
$address3 = $this->input->post('address3[]');
$town = $this->input->post('town');
$postCode = $this->input->post('postCode');
$blockUnits = $this->input->post('blockUnits');
echo print_r($_POST);
$unitNames = $this->input->post('unitName', TRUE);
echo $unitNames[0].'<br />';
if (is_array($unitNames)) {
foreach( $unitNames as $unitName ) {
echo "unit Name is : " . $unitName;
}
} else {
echo "unit is not array";
}
$ownerNames = $this->input->post('ownerName', TRUE);
echo $ownerNames[0].'<br />';
if (is_array($ownerNames)) {
foreach( $ownerNames as $ownerName ) {
echo "Owner Name is : " . $ownerName;
}
} else {
echo "Owner is not array";
}
$salutations = $this->input->post('salutation', TRUE);
echo $salutations[0].'<br />';
if (is_array($salutations)) {
foreach( $salutations as $salutation ) {
echo "salutation is : " . $salutation;
}
} else {
echo "salutation is not array";
}
它显示“所有者不是数组”;这表明数组是空的,经过调试我发现使用print_r,该数组确实是空的,没有发布任何内容......