ExpressionEngine CMS
Open, Free, Amazing
Brought to you by


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


    9 posts


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


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


    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


    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


    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


    9 posts

    Problem solved thanx guys

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

ExpressionEngine News!

#eecms, #events, #releases