Welcome Guest, Not a member yet? Register   Sign In
using set_select() inside php loop
#1

[eluser]Unknown[/eluser]
Hello,

How to use set_select inside PHP loop, like example below:

Code:
<select name='rack_name'>
&lt;?php
foreach ($racks as $row)
{
   echo '<option value="'. $row->rack_id .'" '. set_select("rack_name", $row->rack_id) .'>'. $row->rack_name .'</option>';
}
?&gt;
</select>


Thank you
#2

[eluser]LuckyFella73[/eluser]
Your example seems to be ok - did you try and got an error message?
#3

[eluser]Ahaenor[/eluser]
Hello,

seems like i'm having the same issue. My repopulation code is very close to azzzf's example, but i can't get repopulation of the select field. set_select() just returns an empty string in any case (field value is in the $_POST and thus in the $this->input->post()).

I'd be thankful for some hint.

EDIT:
Found some threads on this issue. Most likely it's a validation class bug. To fix it and repopulate your select (and other) fields, you must set the validation rule explicitly:
Code:
$this->form_validation->set_rules('field_name', 'Field title/label', 'validation_rules (or leave it empty, if field do not need validation)');
or in your application/config/form_validation.php script, if you're using it.

Info is taken from this thread.
#4

[eluser]Ahaenor[/eluser]
[quote author="Ahaenor" date="1274307656"]Hello,

seems like i'm having the same issue. My repopulation code is very close to azzzf's example, but i can't get repopulation of the select field. set_select() just returns an empty string in any case (field value is in the $_POST and thus in the $this->input->post()).

I'd be thankful for some hint.

EDIT:
Found some threads on this issue. Most likely it's a validation class bug. To fix it and repopulate your select (and other) fields, you must set the validation rule explicitly:
Code:
$this->form_validation->set_rules('field_name', 'Field title/label', 'validation_rules (or leave it empty, if field validation is not needed)');
or in your application/config/form_validation.php script, if you're using it.

Info is taken from this thread.[/quote]
#5

[eluser]Unknown[/eluser]
Hello LuckyFella73 and Ahaenor,

Thank you for your reply. As mentioned by Ahanor post above, adding validation rules seem fixed the problem.




Theme © iAndrew 2016 - Forum software by © MyBB