Welcome Guest, Not a member yet? Register   Sign In
accessing field names that have errors?
#1

[eluser]dottedquad[/eluser]
Hello all,
I'm attempting to port my working form validation to the codeigniter form validation way. So far I have:

Code:
<?php

    class validate_livestock_form extends Controller {
        
        function index()
        {
            //set get variables to readable variables
            $species = $this->input->get('species', TRUE);
            $alias = $this->input->get('alias', TRUE);
            $parents = $this->input->get('parents', TRUE);
            $gender = $this->input->get('gender', TRUE);
            $breed = $this->input->get('breed', TRUE);
            $birthdate = $this->input->get('birth_date', TRUE);
            $location = $this->input->get('location', TRUE);
            $comment = $this->input->get('comment', TRUE);
            
            //$this->load->helper(array('form', 'url'));
            
            $validate_field = array();
            
            $this->load->library('form_validation');
            
            $this->form_validation->set_rules($birthdate, 'Birthdate', 'required');
                    
            if ($this->form_validation->run() == FALSE)
            {
                echo json_encode($validate_field);
            }
            else
            {
                echo json_encode($validate_field);
            }
        }
        
    }
?>



My original validation script looped through the form fields and if an error was found set the field name and custom error message to an array (IE: $validate_field = array("birth_date", "Required!")Wink Once the looping is done I did echo json_encode($validate_field); to pass the info over to the form through AJAX.

Now, I'm attempting to port my old script over to codeigniter and have no idea how to do this. So far I stored the $_get['']; variables to their own variables. I'm only validating the $birthdate variable for demo purposes until I get the hang of this. Now I'm trying to figure out how to pass the input field name along with an error msg in JSON form (IE: ["birth_date", "Required"] so the client side can tooltip the error messages by the input field. Any ideas?

-Thanks,
Rich
#2

[eluser]dottedquad[/eluser]
I read a little further and I could just create a validation function. That should work.

-rich




Theme © iAndrew 2016 - Forum software by © MyBB