[eluser]Monarobase[/eluser]
Hello,
The script I'm working on stores in a database the values of an element and allows the user to change them using a drop down list.
I've placed all the values taken from the database in an object called $db to I access them with $db->name
I've got the <select> field in template in the views folder.
In order to select an item I currently have to use the following code :
Code:
<?=set_select('name', 'Name1', (($db->name == 'Name1') ? TRUE : FALSE))?>
And I want to either find a better way to do this or to reduce the code to :
Code:
<?=set_select('critere_ppl', 'Name1', $db->name)?>
So I copied the form_helper.php file from Codigniter's main helpers folder to my applications helpers folder and added some code to the set_select function to ask it to not only look for true but also to compare with the value (I added :
OR $default == $value).
Original code :
Code:
if ( ! isset($_POST[$field]))
{
if (count($_POST) === 0 AND $default == TRUE)
{
return ' selected="selected"';
}
return '';
}
My code :
Code:
if ( ! isset($_POST[$field]))
{
if (count($_POST) === 0 AND ($default == TRUE OR $default == $value))
{
return ' selected="selected"';
}
return '';
}
But this does not seem to change anything, I can only get the selected="selected" if I use TRUE ...
Any ideas what I'm doing wrong ?