Drupal - Webforms as Block - Modifying Action

家住魔仙堡 提交于 2020-01-06 07:01:48

问题


I am using Drupal 7.15, and have a Webform setup as a block that gets included on the Contact page (a basic page). The basic Contact page has editable sidebar content and then the Webform block as the main content. The problem I am having is on submission the Webform goes to its own alias 'general-inqueries' rather than the Contact us alias 'contact-us'. I want it to return to the basic page Contact Us with any validation errors and/or confirmation message.

It seems the form action is always the Webform alias, however when I try to change the alias to the basic page Contact Us alias (contact-us), it says this alias is already in use.

Without creating a separate page for errors or success confirmation, how can I modify the action to return to the original page with any messages on submit? I would prefer not to us JS to set the form action after the fact. That might not even help me anyway if the error/success messages are not passed to it.

Here is the testing server if you would like to take a look:

http://69.160.59.20/contact-us

Any and all help is much appreciated!

Thanks all


回答1:


Form actions can be set using a form_alter hook. Something like:

my_module_form_alter($form, $form_state, $form_id) {
  if ($form_id == 'webform_id_form') {
    $form['#action'] = url('comment/reply/'. $edit['nid']);
  }
}

If you are using Drupal 7 skip the form id check and try:

my_module_form_form_id_alter($form, $form_state) {
}

if you don't know how to find the form id just use the above function with a print statement:

my_module_form_alter($form, $form_state, $form_id) {
  print($form_id);
}

and the form id will be the one with the word webform in it.

More details on the form api here: http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#action



来源:https://stackoverflow.com/questions/12112194/drupal-webforms-as-block-modifying-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!