The web-form works fine . The problem is: The AJAX code above is affecting other forms (Comments form and User Register form).

How is it affecting ?

If other (comment and user-register) forms are submitted successfully in the first time then its fine. But if there is some error in the first time and we submit second time, then click on submit does not perform any action but show ajax effect.

The click on submit button now shows ajax kind of affect but is without any action.

As you can see in the picture, the ajax affect comes in this form. This happens if someone is clicking the button the second time (because of some error on first time).

What could be the possible reason for this and how should I fix this? Thank you in advance.

One way to track this down might be to put a debug statement inside your if() that drupal_set_message()'s or otherwise logs what $form_id is, etc. (And look into the less expensive strpos() vs strstr() when all done :)
–
JimajammaDec 7 '12 at 14:37

@Jimajamma Could you please explain a little more. I really could not do the steps you said. Little more help please. Thank you :)
–
Sandesh YadavDec 14 '12 at 9:26

certainly. if you put a drupal_set_message('I am about to modify ' . $form_id); inside your if..., it might shed light into why that if is succeeding on forms your don't expect it to. If you aren't seeing the above message, you could change it to watchdog('YOURMODULE','I am about to modify ' . $form_id); and then, provided you have dblog()ing turned on, see it in your reports.
–
JimajammaDec 14 '12 at 15:58

I have tried printing $form_id using print and then die() function. It shows $form_id as 13 which is correct $form_id of the webform. I am updating the question by adding the code in the callback function alterwebform_webform_js_submit(). Please see the question once again because the cause can be callback function too.
–
Sandesh YadavDec 15 '12 at 6:34

1

It's unclear whether or not the above code is even being called, inappropriately, for the failed 'comment form and user-registration form' or the ajax form is caused from some other code. As jimajamma suggest, add in debug messages to detect if the above code is being called on the comment and registration forms. If the above code is being called on those forms, then you might consider (hook_form_BASE_FORM_ID_alter)[api.drupal.org/api/drupal/modules!system!system.api.php/… to narrow down which form the code should work on.
–
jhrDec 15 '12 at 10:15

Thanks a lot. Changing the id works. Awesome !! But by the time I got the answer, I have already created one custom form(not using the webform) :) . So now my confusion is which should I choose now. The form that I built from custom module or the already existing webform. Could you please tell me which would be better to use ?? Thanks a lot again !!
–
Sandesh YadavDec 17 '12 at 12:00

If you want just send emails - use webform. If you create your own submit handler for specific actions - you can use your own form and don't use webform module at all.
–
Eugene FidelinDec 17 '12 at 12:04

For now the need is only sending emails. So I will use webform . Thanks again :)
–
Sandesh YadavDec 17 '12 at 12:22