Welcome Guest, Not a member yet? Register   Sign In
Trouble with set_value() & callback form validation
#1

[eluser]lennierb5[/eluser]
I have the following set_rules for my form validation:
Code:
$this->form_validation->set_rules('code_1', 'Billing Code #1','trim|alpha_numeric|callback__validate_billing_codes');

The function it calls back to:

Code:
function _validate_billing_codes() {
        if ($this->input->post('code_1') || $this->input->post('code_7') ||
            $this->input->post('code_2') || $this->input->post('code_8') ||
            $this->input->post('code_3') || $this->input->post('code_9') ||
            $this->input->post('code_4') || $this->input->post('code_10') ||
            $this->input->post('code_5') || $this->input->post('code_11') ||
            $this->input->post('code_6') || $this->input->post('code_12')) {
            $query = $this->db->query('SELECT billing_codes.Codes FROM billing_codes');
            $i = 1;
            while ($i <= 12) {
            if ($_POST['code_'.$i.'']) {
            $_POST['code_'.$i.''] = strtoupper($_POST['code_'.$i.'']);
            if (!in_multiarray($_POST['code_'.$i.''],$query->result_array())) {
                $this->form_validation->set_message('_validate_billing_codes', 'Billing code #'.$i.' is not a valid billing code.');
                return FALSE;
                } } $i++;}
            } else {
            return TRUE; } }

Now my problem is when I try to echo set_value('code_1'); It only works if there were no other validation errors before it on the form. But I can access the value using $_POST['code_1']; set_value 2-12 work just fine with no problems it is only code_1 that has trouble. Any suggestions as to why this is happening? I am temporarily using the $_POST['code_1'] solution.
#2

[eluser]InsiteFX[/eluser]
PHP arrays are 0 based - Try $i = 0;

InsiteFX
#3

[eluser]lennierb5[/eluser]
That produced an error since code_0 does not exist. I actually worked around this by putting my callback function in a hidden field that didn't need to be validated. No problems with set_value then.

I am using CI 2.0 not sure if this could be a bug or if is an odd error somewhere else in my code.




Theme © iAndrew 2016 - Forum software by © MyBB