![]() |
set_value, validation, and form re-population - 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: set_value, validation, and form re-population (/showthread.php?tid=15173) |
set_value, validation, and form re-population - El Forum - 01-28-2009 [eluser]tim1965[/eluser] Hi Having looked through the forum this morning, there seems to be an issue with re-populating fields with any of the set functions for a field that doesnt require any form of validation. It seems you can spoof this by adding the field names to the validation rules, but without applying any rules i.e. just supplying the name. I tried this on my form and it seems to work for everything except set_checkbox fields (of which unfortunately i have many). So my question is can anybody confirm if this is working for them using this method, or should i be looking at another method (of which there seem to be a few) to handle this. set_value, validation, and form re-population - El Forum - 01-28-2009 [eluser]Bramme[/eluser] You're correct: set_stuff functions only work when you have added them to the validation library. You don't have to add any rules indeed. set_value, validation, and form re-population - El Forum - 01-28-2009 [eluser]tim1965[/eluser] Ok thanks Specifically set_checkbox is not working for me, even though i have included them in my validation rules. Below is a group of checkboxes that wont re-populate, although other fields on the form do. <label for="english">English</label> <input name="english" type="checkbox" id="english" value="English"<?php echo set_checkbox('english','1'); ?> /> , <label for="spanish">Spanish</label> <input name="spanish" type="checkbox" id="spanish" value="Spanish"<?php echo set_checkbox('spanish','1'); ?> /> , <label for="french">French</label> <input name="french" type="checkbox" id="french" value="French"<?php echo set_checkbox('french','1'); ?> /> , <label for="german">German</label> <input name="german" type="checkbox" id="german" value="German"<?php echo set_checkbox('german','1'); ?> /> , <label for="portugese">Portugese</label> <input name="portugese" type="checkbox" id="portugese" value="Portugese"<?php echo set_checkbox('portugese','1'); ?> /> , <label for="italian">Italian</label> <input name="italian" type="checkbox" id="italian" value="Italian"<?php echo set_checkbox('italian','1'); ?> /> this is my spoof rules validation for these, they are the fields marked english, french, etc $this->form_validation->set_rules('title', 'Title', 'trim|required'); $this->form_validation->set_rules('first_name', 'First Name', 'trim|required|max_length[50]|alpha_dash_space'); $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|max_length[50]|alpha_dash_space'); $this->form_validation->set_rules('firstlineofaddress', '1st line of Address', 'trim|required|max_length[50]|alpha_dash_space'); $this->form_validation->set_rules('secondlineofaddress', '2nd line of Address', 'trim|max_length[50]|alpha_dash_space'); $this->form_validation->set_rules('townorcity', 'Town or City', 'trim|required|max_length[50]|alpha_dash_space'); $this->form_validation->set_rules('provinceorcounty', 'Province, County or State', 'trim|required|max_length[50]|alpha_dash_space'); $this->form_validation->set_rules('postcode', 'Post\Zip code', 'trim|required|max_length[15]|alpha_dash_space'); $this->form_validation->set_rules('country', 'Country', 'required|max_length[50]|alpha_dash_space'); $this->form_validation->set_rules('contactnotes', 'Contact Notes', 'trim|required|max_length[300]|alpha_dash_space'); $this->form_validation->set_rules('contactpref', '', ''); $this->form_validation->set_rules('english', '', ''); $this->form_validation->set_rules('spanish', '', ''); $this->form_validation->set_rules('french', '', ''); $this->form_validation->set_rules('german', '', ''); $this->form_validation->set_rules('portugese', '', ''); $this->form_validation->set_rules('italian', '', ''); $this->form_validation->set_rules('languageother', 'Other language', 'trim|max_length[30]|alpha_dash_space'); $this->form_validation->set_rules('adverttype', 'Type of advert', 'required'); $this->form_validation->set_rules('terms', 'Accept our Terms', 'required'); Would appreciate somebody eyeballing this for me then if they have the time, to see if i am missing something, as this all looks good to me. And i dont particularly want to have to break the controller apart to go down another route. Thanks in advance. set_value, validation, and form re-population - El Forum - 01-28-2009 [eluser]cwt137[/eluser] Why not give all of those language check boxes the same name? set_value, validation, and form re-population - El Forum - 01-28-2009 [eluser]Bramme[/eluser] Indeed, it would make much more sense to call them all language[] and then give them a proper value. Much easier to loop through. set_value, validation, and form re-population - El Forum - 01-29-2009 [eluser]Hartimer[/eluser] This means that for a "set_value()" function to work i have to add a rule, though empty, to the form validation? set_value, validation, and form re-population - El Forum - 01-30-2009 [eluser]tim1965[/eluser] Hartimer See the last post on this thread Quote:http://ellislab.com/forums/viewthread/102734/ Quote:I used this example and now have checkboxes populating correctly. You will only need one validation rule per checkbox group. Many thanks for people taking time out to help me on this. |