Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Grouping fields together in Fieldset class
  • I'm using the Fieldset class to output a form. All good, I have modified the field template so that each field is wrapped in the DIV structure I need. Only one problem - I need some fields to appear in the same DIV, i.e. grouped together on one line. For example, when outputting a group of date select fields, I need them to appear grouped together, on one line. Any ideas on how I can do this? What is the difference between the 'field_template' and 'multi_field_template' in the form config? Thanks!
  • multi_field_template is used for radio button and checkbox collections (= that have multiple options). It is possible to add a fieldset to another fieldset (nest them). So what you can try is to create a second fieldset for the group of date fields, and give that fieldset a template that will put them on one row. Then add this to the fieldset used to generate the form.
  • Great - thanks for the suggestion. How and where can I define a second fieldset template?
  • You can pass a custom config to a fieldset using set_config(). A snippet from one of my applications:
    // fetch the defined form config
    $formdata = \Config::get('form');
    
    // add a form header
    $formdata['form_template'] = str_replace('{legend}', __('global.information'), $formdata['form_template']);
    $formdata['form_template'] = str_replace('{info}', $info, $formdata['form_template']);
    $formdata['form_template'] = str_replace('{header}', $title, $formdata['form_template']);
    
    // add buttons
    $formdata['form_template'] = str_replace('{buttons}',
     Form::submit('formbutton[save]', __('global.save'), array('id' => 'form_formbutton[save]', 'class' => 'formbutton positive')).
     Form::submit('formbutton[refresh]', __('global.refresh'), array('id' => 'form_formbutton[refresh]', 'class' => 'formbutton', 'formnovalidate')).
     Form::submit('formbutton[cancel]', __('global.cancel'), array('id' => 'form_formbutton[cancel]', 'class' => 'formbutton negative', 'formnovalidate')),
     $formdata['form_template']
    );
    
    // create the fieldset
    $fieldset = Fieldset::forge('users')->set_config($formdata)->set_config(array('form_attributes' => array('onsubmit' => 'fuel_set_csrf_token(this)')))->add_model($model)->populate($model, true);
    

Howdy, Stranger!

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

In this Discussion