嗨,我需要验证这样的多维形式
<input type="text" class="input-xlarge span5 req" id="contact_first_name" name="hotel[<?=$id?>][contact_first_name]" value="<?= set_value('hotel[contact_first_name]') ?>">
<input type="text" class="input-xlarge span5 req" id="contact_last_name" name="hotel[<?=$id?>][contact_last_name]" value="<?= set_value('hotel[contact_last_name]') ?>">
Run Code Online (Sandbox Code Playgroud)
我不知道最终数组的维度,因为输入是通过jquery动态添加的.
我在服务器端使用Codeigniter Form_Validation,在客户端使用JQuery Validator通过JQuery.
这是我的form_validation规则
$config['add_hotel'] = array(
array(
'field' => 'hotel[][hotel_name]',
'label' => 'Hotel Name',
'rules' => 'required'
),
array(
'field' => 'hotel[][contact_first_name]',
'label' => 'First Name',
'rules' => 'trim|required'
),
array(
'field' => 'hotel[][contact_last_name]',
'label' => 'Last Name',
'rules' => 'trim|required'
),
Run Code Online (Sandbox Code Playgroud)
这就是我通过jquery验证器做的方式
$("#add_hotel").validate({
rules: {
"hotel[][hotel_name]": "required"
/* errorElement: "div",
wrapper: "div"*/
},
messages: {
"hotel[][hotel_name]": …Run Code Online (Sandbox Code Playgroud)