![]() |
Get validation rules - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Get validation rules (/showthread.php?tid=16472) Pages:
1
2
|
Get validation rules - El Forum - 03-07-2009 [eluser]bas_vdl[/eluser] Hi there, is it possible to get a array or string of the validation rules set for a form field? i'm building a live validation library for CI and i will pass an extra variable to the form_helper. <?php echo form_input(array('name' => 'first_name', 'validation' => 'required|max_length[10]')); ?> but i want to grab the value "required|max_length[10]" from out of the form_validation files. how do i have to do that? or maybe it is better to grab the values in the form_helper.php files and renerate the textfield with the extra values... in the end i need the values "required|max_length[10]" in my javascript file as soon as the cursor leaves the textfield. thank you for your time regards Bas Get validation rules - El Forum - 03-07-2009 [eluser]TheFuzzy0ne[/eluser] Welcome to the CodeIgniter community! I don't understand. You have to manually set the validation rules in order for the validation to run, so why can't you just re-use that array? Code: $rules = array( // <-- Your validation rules are here! Get validation rules - El Forum - 03-08-2009 [eluser]bas_vdl[/eluser] i have a file form_validation.php. at the moment a user has filled in a text field i will check with jquery if it filled in right. so i thought, if i can read the validation rules from out of the form_validation file and put them in a HTML attribute i can read this and check in my javascript file. so maybe it is a good idea at the moment that the form_helper the text field build he grabs the validation rules that belongs to the text field and pass them in a html attribute. so you get something similar like: <input name="firs_name" validation="required|alpha" /> with the unblur function i can pass the validation attributes en chec live if a field is filled in correctly. Code: <?php Get validation rules - El Forum - 03-08-2009 [eluser]TheFuzzy0ne[/eluser] Code: $this->load->config('form_validation', TRUE); And then you can extract the part of the array you need. Code: $form_validation = $this->config->item('form_validation', 'login'); Get validation rules - El Forum - 03-08-2009 [eluser]bas_vdl[/eluser] [quote author="TheFuzzy0ne" date="1236532175"] Code: $this->load->config('form_validation', TRUE); And then you can extract the part of the array you need. Code: $form_validation = $this->config->item('form_validation', 'login'); Code: $this->load->config('form_validation', TRUE); what means the second (true) parameter? Get validation rules - El Forum - 03-09-2009 [eluser]Tom Schlick[/eluser] it makes it go into a sub array called form_validation to avoid collisions with other config values Get validation rules - El Forum - 03-10-2009 [eluser]bas_vdl[/eluser] i can not use this in the form helper, anyboudy an idea? Get validation rules - El Forum - 03-10-2009 [eluser]TheFuzzy0ne[/eluser] Why can't you use this in the form helper? Get validation rules - El Forum - 03-10-2009 [eluser]xwero[/eluser] Code: function get_validation($field) Code: <input type="text" name="text"<?php echo get_validation('text') ?>> Get validation rules - El Forum - 03-11-2009 [eluser]bas_vdl[/eluser] when i use this method in the form_helper file it will return an empty array, what is wrong? function get_validation($field) { $CI =& get_instance(); $CI->load->library('form_validation'); print_r($CI->form_validation->_field_data); //EMPTY ARRAY if( ! isset($CI->form_validation->_field_data[$field])) { return 'error'; } return ' validation="'.$CI->form_validation->_field_data[$field]['rules'].'"'; } |