I am building on an existing site, adding / modifying functionality to it.

There is a form, which is a part of a (sort of a) multi-step form which I need to alter, and add another form to it.

So, I added the following to the existing form:

// Some form elements above this.
$form['new_form_element']['search'] = drupal_get_form('MY_PROJECT_search_form');
// Some form elements after this

And the MY_PROJECT_search_form function returns the form, which is then embedded in the original form. The form is rendered properly.

However, when I submit the form, I get the following notice :

The form has become outdated. Copy any unsaved work in the form below and then reload this page.

I believe that is because the two forms are getting submitted at the same time, and the submission of one of them is failing.
I have tried adding $form_state['rebuild'] = TRUE to the submit functions, but it did not work.
I have also tried adding an markup type field and embedding form in as
'#markup' = render(drupal_get_form('MY_PROJECT_search_form')); But, I am not able to implement AJAX in the embedded form after that.

Is there any other better way to embed a form?

Note: There is no other option then to embed a separate form to the current form.

  • what about adding the elements of the embedded form to the original form, and adjust/split in the submit handler? Not terribly pretty, but could be a temporary solution
    – Geoff
    Commented May 22, 2015 at 5:29
  • @Geoff I was afraid that would be last option, until I come up with a better solution. But, as you said it could be used as a temporary solution.
    – AjitS
    Commented May 22, 2015 at 5:51
  • take a look at this question - it could be doing something similar
    – Geoff
    Commented May 22, 2015 at 5:56

1 Answer 1


Nesting forms in other forms is not valid in html. see this post html nesting forms in forms

You can always try calling the form directly via the actual form function instead of via drupal_get_form since the function returns a valid array of form elements. you'll have to somehow compensate for the missing hook_form_alter and hook_form_FORM_ID_alter.

Note I haven't actually tried this, so I'm not sure how it will react on the empty $form/$form_state params.

That already gets you all the fields in a dynamic way. Perhaps you can build a similar work around calling the submit/validate handlers directly too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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