Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I created a module to hook the webform using the hook_form_alter.This converted the webform into AJAX form. This worked on localhost . But when I installed the same module to web server , it does not work.

This is the main code part of the module.

function alterwebform_form_alter(&$form, &$form_state, $form_id) {

if(strstr($form_id, 'webform_client_form_')) {  

$nid = $form['#node']->nid;

$form['actions']['submit']['#ajax'] = array(
  'callback' => 'alterwebform_webform_js_submit',
  'wrapper' => 'webform-client-form-' . $nid,
  'method' => 'replace',
  'effect' => 'fade',
);
}
 $form['actions']['submit']['#validate']= array('alterwebform_ajax_myform_validate');
}

//this is the callback function.

function alterwebform_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;
    }
  }

Any hint or suggestion please . Thank you .

share|improve this question

2 Answers

What do you mean by "does not work"? I recommend that you use a tool like Firebug (and its NET panel) to debug what is happening with your AJAX call on the server and compare that with what happens on your local server.

share|improve this answer
I did that and the form-id were same in both the cases. What are other things on which the working of the AJAX would depend ? Thanks for the response . – sandesh yadav Jul 8 '12 at 3:03
I still don't know what you mean by "does not work". But I suspect that rather than the form ID, you should use Firebug's NET panel to see whether the AJAX calls are being made and returned successfully; it's usually a path issue. – user7667 Jul 8 '12 at 8:04
It 'does not work' mean when I submit the form , the page reloads instead of replacing the desired block with confirmation message . One more thing I would like to ask is when I see in firebug the form ID in some pages is 'webform-client-form-13--2' instead of 'webform-client-form-13'. Why form ID changes in some pages ? Thank you . – sandesh yadav Jul 8 '12 at 9:55

The else clause in your ajax callback is returning the entire form; it's possible the else clause is being triggered rather than the if clause as you intend.

BTW, I'd avoid using the word "submit" in your ajax callback, as the submit callback and ajax callback are two different things.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.