ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dropdown default value

July 16, 2009 10:32am

Subscribe [3]
  • #1 / Jul 16, 2009 10:32am

    Ninja's avatar

    Ninja

    9 posts

    Controller

    $client = new Client();
                $client->get('id');
        
                foreach($client->all as $entry)
                {
                    $clientID = $entry->id;
                    $entry->company->get('companyname');
                    $companyName = $entry->company->companyname;
                    $data['parent'][$clientID] = $companyName;    
                }

    View

    <?php echo form_dropdown('Parent', $parent )?>

    Im trying to set the default value for the dropdown to something like “Not Applicable”
    With an index of 0. This dropdown is for Parent clients (ie. The client of a client) but not all clients will have a parent client.

  • #2 / Jul 16, 2009 10:59am

    steelaz's avatar

    steelaz

    252 posts

    Assuming “Not Applicable” option index is 0:

    <?= form_dropdown('Parent', $parent, 0)?>


    Also… wrong forum, next time try: Code and Application Development

  • #3 / Jul 16, 2009 11:06am

    davidbehler's avatar

    davidbehler

    708 posts

    If you use the form validation, you could use the set_value function:

    <?= form_dropdown('Parent', $parent, set_value('Parent', 0))?>

    That way the default value is 0 but if the form was submitted and did not validate, the selected value will be kept instead of resetting it to 0.

  • #4 / Jul 17, 2009 3:12am

    Ninja's avatar

    Ninja

    9 posts

    I have tried both of those options but i think the problem is that “Not Applicable” with index 0 is not in the array and i cant seem to add it to the array.. The array is being populated from the database table clients. which has 3 fields id, parent_client, company_id.

  • #5 / Jul 17, 2009 3:31am

    Thorpe Obazee

    1138 posts

  • #6 / Jul 17, 2009 7:43am

    Ninja's avatar

    Ninja

    9 posts

    Problem solved thanx guys

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases