0

Question / Situation

We want to validate a webform (through webform_ajax) which is dynamically loaded with AJAX.

Steps (desired)

  1. Visitors clicks on link
  2. Data is loaded in a DIV (jQuery AJAX Load)
  3. Form is rendered and can be send (with validation and AJAX send)

Problem

When submitting the form the AJAX validation won't trigger and the visitor is send to the corresponding node (next page). How can we setup Drupal to accomplish the desired steps? We use the following Modules and we've tried several techniques, see Tested below.

Technical problem

On a normal node the webform has Drupal.settings, but when loaded with AJAX there are no Drupal.settings for the webform. The Drupal.settings include a Node-ID which is used on the parent wrapper DIV (example: #webform-ajax-wrapper-127). Stripping the ID at the end for global use didn't work.

Main question

How can we solve this problem?

Sub questions (separate or steps to solve this problem)

  1. What is the best way to include JS after an AJAX load (new content)?
  2. How can we (re)initiate the Webform/Webform AJAX on the new content?
  3. How can we add custom/new Webform Drupal.settings?

Tested

  • Behaviors: $('div').ajaxComplete(function(){Drupal.attachBehaviors(DIV);});
  • Inserting JS to page drupal_add_js('sites/all/modules/webform/js/webform.js');
  • Inserting an other webform to use the code for the new content.

Modules for function

  • jQuery AJAX Load
  • Webform
  • Webform Ajax

Modules on page

  • Panels
  • Views

Can you help me in the right direction? What is your experience to accomplish this?

  • [This answer](http://stackoverflow.com/questions/23229962/loading-views-accordion-through-an-ajax-request/23326690#23326690) explains how to include missing javascript along with an AJAX-requested content. After reading it, you can probably solve (at least) subquestion 1. – EricLavault May 01 '14 at 15:14
  • Thanks, but how can we manage to get this working in a panel? – Tommy Janssen May 13 '14 at 09:54

1 Answers1

0

In submit callback function, clear fields like:

function SUBMIT_CALLBACK($form, $form_state) {
  $sid = $form_state['values']['details']['sid'];
  if ($sid) { // Success in submitted.
    $form['submitted']['FIELDNAME1']['#value'] = '';
    $form['submitted']['FIELDNAME2']['#value'] = '';
  }
  return $form;
}

Ref to http://envisioninteractive.com/drupal/add-ajax-to-a-webform-in-drupal-7/

Henry
  • 1,077
  • 1
  • 16
  • 41