Welcome Guest, Not a member yet? Register   Sign In
set_value, validation, and form re-population
#1

[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.
#2

[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.
#3

[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>
&lt;input name="english" type="checkbox" id="english" value="English"&lt;?php echo set_checkbox('english','1'); ?&gt; /&gt;
,
<label for="spanish">Spanish</label>
&lt;input name="spanish" type="checkbox" id="spanish" value="Spanish"&lt;?php echo set_checkbox('spanish','1'); ?&gt; /&gt;
,
<label for="french">French</label>
&lt;input name="french" type="checkbox" id="french" value="French"&lt;?php echo set_checkbox('french','1'); ?&gt; /&gt;
,
<label for="german">German</label>
&lt;input name="german" type="checkbox" id="german" value="German"&lt;?php echo set_checkbox('german','1'); ?&gt; /&gt;
,
<label for="portugese">Portugese</label>
&lt;input name="portugese" type="checkbox" id="portugese" value="Portugese"&lt;?php echo set_checkbox('portugese','1'); ?&gt; /&gt;
,
<label for="italian">Italian</label>
&lt;input name="italian" type="checkbox" id="italian" value="Italian"&lt;?php echo set_checkbox('italian','1'); ?&gt; /&gt;

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.
#4

[eluser]cwt137[/eluser]
Why not give all of those language check boxes the same name?
#5

[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.
#6

[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?
#7

[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.




Theme © iAndrew 2016 - Forum software by © MyBB