Welcome Guest, Not a member yet? Register   Sign In
Client+Server-side validation
#1

[eluser]xtramix[/eluser]
Here's my first attempt at implementing automatic generation of the javascript code for client-side validation using CI standard validation rules:

1. Somewhere in your controller, add a method defining your validation rules:
Code:
function setup_validation()
{
    $this->load->library('validation');
    ...
    $this->validation->set_rules($rules);
}

2. Call this method when displaying web form. The client-side validation javascript will be automatically created for you.
Code:
$this->setup_validation();        
$data['javascript'] = $this->validation->javascript();
$this->load->view('view', $data);

3. Call the exact same method again when processing submitted form data on the server side, as usual:
Code:
$this->setup_validation();        
if ($this->validation->run() == true)
{
    ... etc.
}


To install, place MY_Validation.php class in application/libraries folder.

For more info, see CI Wiki
#2

[eluser]qICEp[/eluser]
Can you please provide download for MY_Validation.php ? GitHub escaped/striped some tags and its pain in the ass to figure out what is what and return it the way it was...(even with find and replace)
For example most of the < tags have been replaced with
Code:
& l t ;

Will CI load jQuery.validation.js automaticly when its needed or....(didnt see it in a code and didnt read that we need to include it)

And what about custom error messages on a client side?
Code:
$this->form_validation->set_message('rule', 'Error Message');
We use it like that?
#3

[eluser]quickshiftin[/eluser]
Nice work!




Theme © iAndrew 2016 - Forum software by © MyBB