CodeIgniter - 对字符串化后发送的AJAX数据(多维关联数组)进行表单验证

时间:2014-08-29 13:20:39

标签: javascript php jquery ajax codeigniter

这是javascript部分的快速演示:

            var student = {};

            student['name'] = 'ABC';
            student['dob'] = '1-1-2015';
            student['address'] = {};
            student['address']['home'] = 'somewhere on earth';
            student['address']['office'] = 'near mars';
            student['contactnum'] = {};
            student['contactnum']['home'] = {};
            student['contactnum']['home']['mob'] = '12345';
            student['contactnum']['home']['phone'] = '987';
            student['contactnum']['office'] = {};
            student['contactnum']['office']['mob'] = '12345';
            student['contactnum']['office']['phone'] = '987';

            $.ajax({
                type: "POST",
                url: "<?php echo base_url('admin/ajax/addStudent');?>",
                data: {'d': JSON.stringify( student ) },
                contentType: 'application/json'
            })

正如您所看到的那样,通过AJAX将此关联数组对象发送到CodeIgniter页面。但问题是,如何在服务器端使用FormValidation helper!据我所知,验证助手只检查单个字段名称。由于我需要的所有验证都在那个帮手中,我不想重新发明轮子,但想知道如何在CodeIgniter页面上为这些数据编写验证配置!

0 个答案:

没有答案