Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
form select from array with empty option
  • Hi, So I retrieve a list of users from a database and add it to an array so I can fill out a selectbox like so:
    $users = Model_User::find()->where('id', '!=', $this->user_id)->get();
    foreach($users as $user)
        $users_list[$user->id] = $user->username;
    

    In my view I just use
    <?php echo Form::select('users', null, $users_list); ?>
    

    This works, but how should I add an empty option to the array and check for it in my validation?
  • Oh... nvm, Had to drink coffee to notice how simple it is.
    As you can't have id "0" in your database, I did:
    $users_list[0] = "";
    

    before the foreach.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion