Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
form select issues
  • Hi, I'm amazed the optgroup tag is already implemented using an array in an array :D
    But what I can't find is how to set the previous value?
    for example for an input it's easy:
    <?php echo Form::input('prijs', e($val->input('prijs')), array('size' => '10')); ?>
    

    but for a select how would I write it?
    for example if this is my code:
    echo Form::select('country', 'none', $category);
    

    $category is an array of my categories and sub-categories.
  • The pre-select value (or array of values in case of a multi-select) is the second parameter of Form::select().
  • sigh... offcourse :D
    As in the example was written 'None' I thought the value meant something else.
  • In the example, 'none' refers the the first element in the values array...
  • Is it possible to make the first one none selectable?
    So it wont be saved.
  • I don't understand what you mean. If you don't provide a pre-select value, your browser is going the select the first option in the dropdown, this is by design. If you don't want that, add a dummy value as first option to the values array, as it's done in the documentation (this is what's meant by 'none'). I usually add a '0' => 'none selected' as first option, where '0' is whatever the default value of your database column is.
  • Well thats the problem there is no default in my database.
    They need to pick a choice. But if I create a dummy I suppose that dummy is also selectable. If it's selectable it's possible to save it, I dont want that :)
  • Capture the dummy value in your validation or in your controller code, and return a "please select a value" message. You should validate all input before saving it into the database anyway.

Howdy, Stranger!

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

In this Discussion