提交Drupal 7 Webforms时如何使用Ajax?

时间:2014-11-06 15:20:37

标签: ajax drupal drupal-7 drupal-webform

我需要使用AJAX在我的主题基于Bootstrap的模态对话框中提交webforms,并在没有关闭模态的情况下在模态中显示消息。

我找到了解决方案Add AJAX to a Webform in Drupal 7,但是在Bootstrap模式中提交webforms时,模式窗口关闭,所有关于错误成功的消息都显示在标准消息中。

这是模块代码:

<?php
// http://envisioninteractive.com/drupal/add-ajax-to-a-webform-in-drupal-7/
function webform_ajax_submit_form_alter(&$form, &$form_state, $form_id) {
    if(strstr($form_id, 'webform_client_form_')) {
        $nid = $form['#node']->nid;
        // add the ajax properties to the submit button
        $form['actions']['submit']['#ajax'] = array(
            'callback' => 'webform_ajax_submit_webform_js_submit',
            'wrapper'  => 'webform-client-form-' . $nid,
            'method'   => 'replace',
            'effect'   => 'fade',
        );
    }
}

function webform_ajax_submit_webform_js_submit($form, $form_state) {
    $sid = $form_state['values']['details']['sid'];
    if ($sid) {
        $node = node_load($form_state['values']['details']['nid']);
        $confirmation = array(
            '#type'   => 'markup',
            '#markup' => check_markup($node->webform['confirmation'], $node->webform['confirmation_format'], '', TRUE),
        );
        return $confirmation;
    }
    else {
        return $form;
    }
}

我认为$form['actions']['submit']['#ajax'] = array(...)中某处的问题 Webform Ajax并非完全符合我的任务。

1 个答案:

答案 0 :(得分:-1)

解决方案Submit Webforms in Drupal 7 via Ajax (module)但俄语信息(谷歌翻译服务=)))