Load existing form and use hook_form_alter to create a custom submit handler? I have an existing webform in admin and I want to now render that form on other pages. I have a template page node--download_resource_protected.tpl that prints a hidden CSS pop-up box onto pages that show a teaser for content type Download Resource - Protected. When you click on the teaser, this pop-up shows. It currently includes a static form, asking for data-input before access to the download is allowed. See the screenshot here:



Now in place of this static form I want to render an existing webform with the API. The two teasers on the are defined as entity reference fields: Call to Action 1 and Call to Action 2.

After successful completion of the webform I want to post the data to the node URL of the teaser. For example if the page is displaying a teaser of node 34: the user clicks the teaser and the pop-up appears (this already happends), within the popup a webform is rendered (in place of the current static form) and on completion of the form it posts the data and loads URL node/34 (this needs to be dynamic i.e automatically directing to the correct node URL depending on node_id of the teaser).

I want to use hook_form_alter() to set a custom submit handler like this.

 if ($form_id == 'webform_client_form_112') {
    $form['#submit'][] = 'my_custom_submit_handler';
  }


But I need to pass the teaser node id in which the block webform was called, to this custom function (this will then allow me to to redirect to the node URL), any ideas?

Thanks for your time!
You can use the 'Available as block ' for webform settings. This option can find at 'form settings'->Advanced settings of your webform. Once it enabled you can render this webform block, instead of your static form as follows.



You can define custom submit handler for the webform, ex: $
form['#submit'][] = 'my_custom_submit_handler';  in form alter,
in that function you can write the necessary code to save and redirect etc;

hope this may help you.