Problem with set_value() of Form Validation - 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: Problem with set_value() of Form Validation (/showthread.php?tid=17197) |
Problem with set_value() of Form Validation - El Forum - 03-28-2009 [eluser]Italo Domingues[/eluser] Good evening, I wish to inform a problem in the method set_Value () the library form_validation. I have the following form. And I got the script for the validation of some required fields (scripts below). The problem that occurs is, if I fill out the form and leave a required field not filled, it makes the validation perfectly, but when he return to form, the set_Value () returns only the data that are in the script validation, for example, if I enter something in the specification of the product, so it makes the validation of the fields, and return again to the form stating that there is a mandatory field not filled, the field specification of the product does not return what was entered, even though the set_Value () in the attribute value of the input. This is normal? Form Code: <?php echo form_open('admin/produtos/cadastrar', array('id' => 'form_cadastro_produto', 'onSubmit' => 'cadastrarProduto(); return false;')); ?> Script Code: function _verificar_campos() PS: I had to draw some lines of form because it does not fit in the post! Problem with set_value() of Form Validation - El Forum - 03-31-2009 [eluser]Aaron Wallentine[/eluser] I had this exact same problem. Basically, if you use set_value, and you use the Form_validation class, set_value() only actually returns the prepopulated value for fields that have validation rules set for them. I looked into the source code of set_value and found this: If you're not using the form_validation class, it just returns your $_POST data (after processing it through form_prep() ). If you are using the form_validation class, it calls the set_value function from the form_validation object, which looks in its internal $_field_data array for the value. If it doesn't find it, it returns default. I did a print_r on the _field_data array from there, and it appears that it only contains data of fields that have had validation rules defined on them, So, if you want set_value to work for all your fields, it looks like you either: 1. Set up a validation rule for the field(s) in question 2. patch set_value() in form_validation.php to also check $_POST if it doesn't find the value in _field_data 3. don't load the form validation class Should I file a bug report for this? Or is this expected behavior? IE, if I'm using the form validation class, it's assumed that I have at least one rule set for all fields? Problem with set_value() of Form Validation - El Forum - 05-19-2009 [eluser]Unknown[/eluser] just do the trick with set a blank rule, ie : Code: $this->form_validation->set_rules('field_name', '', ''); Problem with set_value() of Form Validation - El Forum - 02-07-2010 [eluser]lolmann[/eluser] [quote author="Agus Tri Mulyanto" date="1242756686"]just do the trick with set a blank rule, ie : Code: $this->form_validation->set_rules('field_name', '', ''); It is an ugly workaround but it works. Took me some time to find this. Would be cool if this bug got fixed. Problem with set_value() of Form Validation - El Forum - 05-30-2011 [eluser]pam81[/eluser] Hi, i have the same problem and I wanna know if was this bug fixed? Problem with set_value() of Form Validation - El Forum - 08-03-2011 [eluser]Pieter[/eluser] I created a My_Form_validation library to solve this problem. It should work with arrays as fieldnames, like profile[name] and colors[] as well. Locate it in your 'application/libraries/My_Form_validation.php'. Hope it helps. Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed.'); Problem with set_value() of Form Validation - El Forum - 08-03-2011 [eluser]Unknown[/eluser] Pieter, thank you for the post on this. It was exactly what I was looking for and solved a couple of issues that I was having with both set_value and form_validation! |