Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Multiple forms in Advanced module

edited April 12 in Modules

Hi

I have an advanced module where I want multiple forms on a single page.

I have this working however only the supercomboselect on the first form is being initialised. On the second form, I see the standard HTML multi-select format.

What am I missing?

Controller:
$form1fields['f1field'] = array('type' => 'multi', 'label'=>'Species', 'options' => my_options_list_a());
$this->form_builder->set_fields($form1fields);
$vars['form1'] = $this->form_builder->render();
$form2fields['f2field'] = array('type' => 'multi', 'label'=>'Species', 'options' => my_options_list_b());
$this->form_builder->set_fields($form2fields);
$vars['form2'] = $this->form_builder->render();
$this->fuel->admin->render('_admin/main', $vars, Fuel_admin::DISPLAY_DEFAULT);

View:
echo $form1;
echo $form2;

Comments

  • That one is tough to tell without the full controller code. One issue may be that the main page area in FUEL is surrounded by a form tag and doesn't allow nesting multiple form tags which may be part of the issue depending on how you setup the page.

    For each render, is it outputting a chunk of javascript similar to below (do a search for "formBuilderFuncs" in the source)?

    <script type="text/javascript">
    
    if (jQuery){ jQuery(function(){if (jQuery.fn.formBuilder) {if (typeof(window['formBuilderFuncs']) == "undefined") { window['formBuilderFuncs'] = {}; };window['formBuilderFuncs'] = jQuery.extend(window['formBuilderFuncs'], {"multi":{"func":"fuel.fields.multi_field","options":null,"order":0}});jQuery("#form_XXXX").formBuilder(window['formBuilderFuncs']);jQuery("#form_XXX").formBuilder().initialize();}})}</script>
    
  • edited April 14

    Yeah. There's a form element wrapping everything, the "correct"(?) [div] container for the first form and then a [form] container for the 2nd form. There's two formBuildFuncs stanzas but both use the ID of the first form.
    Loading the formbuilder library in the controller and building 2 forms doesn't seem to create two separate sets of form code.
    Is there a way to set up a view page that doesn't include that wrapping form?
    I might need to rearrange the way I'm presenting this module - separate pages for each form and a collective menu on the left-hand side...

  • You can set the id on the second form so that it renders with a different ID:

    $form1fields['f1field'] = array('type' => 'multi', 'label'=>'Species', 'options' => my_options_list_a());
    $this->form_builder->set_fields($form1fields);
    $vars['form1'] = $this->form_builder->render();
    
    $this->form_builder->id = 'my-id';
    $form2fields['f2field'] = array('type' => 'multi', 'label'=>'Species', 'options' => my_options_list_b());
    $this->form_builder->set_fields($form2fields);
    $vars['form2'] = $this->form_builder->render();
    $this->fuel->admin->render('_admin/main', $vars, Fuel_admin::DISPLAY_DEFAULT);
    
  • Thanks. Setting $this->form_builder->id was enough to get things working.

Sign In or Register to comment.