挂钩Drupal Webform提交
I'm developing a Drupal 7 website. The website has a couple of forms which take a users email address. As part of the process I need to be able to submit the email to a mailing list across an API.
I have all the calls written and tested for adding new users to mailing lists etc. What I'm not so sure of is how I get this code to run when the form is submitted on the Drupal site.
I assume there will be a hook function but I'm struggling to track it down. My forms are setup using Webforms module.
我正在开发一个Drupal 7网站。 该网站有几种形式,用于收集用户的电子邮件地址。 作为流程的一部分,我需要能够通过API将电子邮件提交到邮件列表。 p>
我已经编写并测试了所有调用以将新用户添加到邮件列表等的调用。 我不太确定的是,当在Drupal站点上提交表单时,我如何运行此代码。 p>
我假设会有一个钩子函数,但我正在努力 跟踪它。 我的表单是使用Webforms模块设置的。 p> div>
Use hook_form_alter()
to hook in your webform instance & add an additional submit handler:
/**
* Implements hook_form_alter().
*/
function hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'webform_client_form_{some id}')
{
array_unshift($form['#submit'], 'custom_webform_submit');
}
}
Next in custom_webform_submit()
execute your custom code:
function custom_webform_submit($form, $form_state) {
// custom code here
}