Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to print a select tag with Fieldset?
  • I really can't figure it out... can somebody help me please?
  • Sorry to revive a slightly older topic, but this came up when I was searching my issue. If fields have already been added based on a model, how would one modify a Select tag to insert options before it's built? Select lists are frequently dynamically generated so it doesn't make sense to define the options in the Model. Model:
    protected static $_properties = array(
     'id',
     'name' => array(  // Array defines column properties for use in forms and validation
      'data_type' => 'varchar',
      'label'     => 'Business Name',
      'form'      => array('type' => 'text'),
      'default'   => 'New business',
      'validation'=> array('required', 'min_length' => array(3)), 
     ),
     'category' => array(
      'data_type' => 'integer',
      'label'  => 'Category',
      'form'  => array(
       'type' => 'select'
      ),
     ),
     'description' => array(
      'data_type' => 'text',
      'label'     => 'Description',
      'form'      => array('type' => 'textarea'),
      'validation'=> array('required', 'min_length' => array(25)),
     )
    );
    
    Controller:
    $edit_fields = Fieldset::forge('edit_business')
        ->add_model('Model_Business');
    
    $cat_input = $edit_fields->field('category');
    
    $cat_input->set_attribute(array('options' => array('3' => 'No value!')));
    
    $edit_form = $edit_fields->form();
    $edit_form->add('submit', '', array('type' => 'submit', 'value' => 'Submit'));
    
    This was my guess but it didn't work, and only looked at the model.
  • That should work without problems. Switching to the form instance isn't very useful, Form::add is an alias for Fieldset::add, this should be enough
    $edit_fields = Fieldset::forge('edit_business') ->add_model('Model_Business');
    $edit_fields->field('category')->set_attribute(array('options' => array('3' => 'No value!')));
    $edit_fields->add('submit', '', array('type' => 'submit', 'value' => 'Submit'));
    

    I use this all the time, so I wouldn't know why I doesn't work in your case.
  • From one of my apps:
    // create the fieldset for the exam voucher
      $voucherform = Fieldset::forge('voucherform');
      $voucherform->add('voucher', 'Geef uw examen code in');
    
      // create the fieldset for the payment method
      $options = array('0' => '', 'IDEAL' => 'Betaal via iDEAL');
      Auth::has_access('access.user') and $options['ACCOUNT'] = 'Op rekening';
      $voucherform->add('methode', 'Gewenste betaal methode', array('type' => 'select', 'options' => $options));
    
  • Harro Verton wrote on Friday 27th of July 2012:
    From one of my apps:
    // create the fieldset for the exam voucher
      $voucherform = Fieldset::forge('voucherform');
      $voucherform->add('voucher', 'Geef uw examen code in');
    
      // create the fieldset for the payment method
      $options = array('0' => '', 'IDEAL' => 'Betaal via iDEAL');
      Auth::has_access('access.user') and $options['ACCOUNT'] = 'Op rekening';
      $voucherform->add('methode', 'Gewenste betaal methode', array('type' => 'select', 'options' => $options));
    

    Many thanks! :)
  • ... And what about pre-select a specific option?
  • Should be
    $voucherform->add('methode', 'Gewenste betaal methode', array('type' => 'select', 'value' => $preselect_value, 'options' => $options));
    

Howdy, Stranger!

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

In this Discussion