1

I have a hook_field_widget_form where I call drupal_get_form multiple times.

Here is my code:

foreach ($suppliers AS $supplier_id => $supplier) {
    $delivery_information = sbsl_order_delivery_information_new();

    $element['suppliers'][$supplier_id] = array(
      '#type' => 'fieldset',
      '#title' => $supplier['supplier_information']['visible_name'],
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );

    $delivery_information_form = drupal_get_form('sbsl_order_delivery_information_1_form_' . $supplier_id);
    $element['suppliers'][$supplier_id]['delivery_information'] = $delivery_information_form;
  }

How can I remove the submit button on the form included by drupal_get_form, and only use the submit of hook_field_widget_form to submit all the forms included by drupal_get_form?

  • Can you make the question more specific by adding some code? – tvl Oct 30 '14 at 10:55
  • Now i have updated the question – Jesper Bay Eriksen Oct 30 '14 at 12:57
0

If you look at the function drupal_render it will ignore all elements marked as #printed so just add that to the submit button's array.

You'll need to inspect the $delivery_information_form array to see exactly where your button is at, and when you find it you can do something like this:

  $delivery_information_form = drupal_get_form('sbsl_order_delivery_information_1_form_' . $supplier_id);
  $delivery_information_form['path']['to']['button']['#printed'] = TRUE;

before adding it to the $element array.

  • and how might this help him? can you provide a change to his code to solve his problem? – tenken Oct 30 '14 at 20:17
  • @tenken I don't know the structure of the form to be embedded, he'd need to drill through the array returned by drupal_get_form to find the buttons in order to add that property. – Coleman Oct 30 '14 at 20:19
  • When i submit my widget, it seems that the form is only submited once no matter how many times the form is used. – Jesper Bay Eriksen Nov 4 '14 at 11:29
  • It seems your basic premise is flawed - you were expecting the submit handler for the embedded form to be invoked multiple times? I think the correct approach here would be for delivery_information_form to generate the correct number of fieldsets needed using a foreach loop based on the number of suppliers. – Coleman Nov 6 '14 at 20:06
  • @JesperBayEriksen but I did give you the correct answer to your question (even though the question was based on some flawed assumptions) so accepting the answer would be much appreciated. – Coleman Nov 6 '14 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.