我正在尝试从总共四个复选框中选择一个复选框,但它不起作用。无论我是否选中复选框,它都会通过验证。
这是我的控制器Cargo_inquiry(){}
中的方法function step_two() {
$country_to_select = $this->session->userdata('freight_address_country');
$this->data['users'] = $this->My_Users_Model->get_companies_list($country_to_select);
// load up the validation rules for blog Info form
$this->config->load('validate_cargo');
$this->form_validation->set_rules($this->config >item('validate_cargo_create_step_two') );
if ($this->form_validation->run('validate_cargo_create_step_two') === FALSE) {
echo "FALSE";
// die;
$this->load->view('_layouts/main/template1', $this->data);
} else {
echo "TRUE";
// die;
redirect('/Cargo_inquiry/step_three');
}
}
以下是我在validate_cargo.php中的验证规则:
$config['validate_cargo_create_step_two'] = array(
'user_id' => array(
'field' => 'user_id',
'label' => '',
'rules' => 'required',
'errors' => array(
'required' => 'Please select at least one company.',
),
),
);
这是我的观点/表格:
<?php echo form_open('Cargo_inquiry/step_three',array('class'=>'form-horizontal'));?>
<table class="table table-bordered table-striped" id="mytable">
<thead>
<tr>
<th width="3%">Select</th>
<th>company</th>
<th>location</th>
<th>rating</th>
<th>web</th>
<th>Associations/serv_hhgpe</th>
</tr>
</thead>
<tbody>
<?php
foreach ($users as $user) { ?>
<tr>
<td>
<?php // echo form_checkbox('user_id[]', 'user_id[]', set_checkbox("user_id[]"), "Company"); ?>
<input type="checkbox" name="user_id" value="<?php echo $user->id; ?>" />
</td>
<td>
<?php echo $user->company ?>
</td>
<td>
<?php echo $user->city ?>
</td>
<td>
<?php echo $user->state_province ?>
</td>
<td>
<?php echo $user->name ?>
</td>
<td style="text-align:center" width="200px">
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php echo form_submit('cargo_create_step_two', 'Next->', 'class="btn btn-primary btn-lg btn-block"');?>
<?php echo form_close();?>
答案 0 :(得分:0)
Arrrgg !!!我提交错误的表格:(非常抱歉。