2014-11-06 21 views
0

我需要使用AJAX提交基於Bootstrap的模態對話框中的webforms,並在模式中顯示消息,而無需關閉模式。如何在提交Drupal 7 Webforms時使用Ajax?

我找到了解決方案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不完全是我的任務。

回答