Validation, re-populating array checkbox |
[eluser]Kopel[/eluser]
Hi, I need to re-populate my checkbox when my form has been submitted with errors. Everything is fine with regular checkbox, but my checkbox has to be an array (name="mycheck[]"). See below my simplified code as an example. - In order to have an error i leave the input blank - I check some boxes - I submit the form - The error on the input is found, the controller reload the form view - The checkboxes are unchecked... I tried all day long to find the solution of this apparently simple problem, but i'm still unsuccessful. Please, let me know what is wrong with my code. Thanks. View file: Code: <?php echo form_open('sandbox'); ?> Controller file Code: <?php
[eluser]Référencement Google[/eluser]
Unfortunaly and we hope that this will come in a next version of CI, it doesn't validate Checkboxes or Radio like other fieds type, so <?php echo $this->validation->error_string; ?> will return nothing. Make a test on $_POST datas should resolve your problem. This could be simply: Code: if(!$this->input->post('mycheck'))
[eluser]Kopel[/eluser]
Thanks for the reply elitemedia. Well, the error string is not my problem. In fact, the user can check/uncheck all or just some of these checkboxes , so they do not generate errors... My concern was about the re-populating of the array checkbox. Especially when the validation failed because of the others widget (like with the input text Username on my example). I lost too much time on this crazy thing today. Finally i did something not as clean as i would but now it works. Anyway, if someone have THE solution, i'm still interested... Thx
[eluser]Référencement Google[/eluser]
Ok, understood. Look at this one: [url="http://ellislab.com/forums/viewthread/51260/"]http://ellislab.com/forums/viewthread/51260/[/url] And read all the thread, there are bug fixes along it.
[eluser]gkchicago[/eluser]
Old thread I know, but I have posted my solution to this problem here: http://ellislab.com/forums/viewthread/79792/
[eluser]vadivelan[/eluser]
Hi Validation of listbox, checkbox groups and reselect multiple values using set_select, set_checkbox / Sol: Array to string conversion error (line 709) http://ellislab.com/forums/viewthread/73012/
[eluser]Nexus Rex[/eluser]
I believe all that was missed in the example in the initial post were the square brackets in the form object name within the set_checkbox() function. The proper name of the checkbox object is "mycheck[]" and NOT "mycheck" Code: <?php echo form_open('sandbox'); ?>
[eluser]Unknown[/eluser]
ok, so I pulled some hair trying to make this work and here is what I come up with as the quickest solution: (in my view) Code: $checkedLangs = $this->input->post('language'); then from validation: Code: $this->form_validation->set_rules('language', 'Language', 'less_than[9999]'); I now its not your example code and i have my own unrelated functions but you should be able to figure it out. - seems like a bit much but you get what you get with someone else's framework i guess |
Welcome Guest, Not a member yet? Register Sign In |