Welcome Guest, Not a member yet? Register   Sign In
Customising a helper (not taken into account) form_helper.php
#1

[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:
&lt;?=set_select('name', 'Name1', (($db->name == 'Name1') ? TRUE : FALSE))?&gt;

And I want to either find a better way to do this or to reduce the code to :

Code:
&lt;?=set_select('critere_ppl', 'Name1', $db->name)?&gt;

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 ?


Messages In This Thread
Customising a helper (not taken into account) form_helper.php - by El Forum - 01-13-2010, 05:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB