开发者

Drupal form continues to get submitted even if jQuery submit() function returns false;

I have a Drupal form,

<form action="/forms/contact.html"  accept-charset="UTF-8" method="post" id="webform-client-form-1148-1" class="webform-client-form" enctype="multipart/form-data"> 

with the following submit,

<input type="submit" name="op" id="edit-submit-1" value="Submit"  class="form-submit" />

The page containing the form loads the following jQuery inline,

jQuery("#webform-client-form-1148-1").submit(function(){return false;});

No matter what I try, the submit button always submits the form. Since I am returning false, I expect the form to disregard the submission process and cancel completely.

Why does the form continue to submit, even though 'return false' is being returned for the form's submit() fu开发者_StackOverflow社区nction?

This is a simple example that I have dumbed down in my code to force submit on the form to always return false, and therefore, should never submit.


I answered a similar question not long ago. Check Stop form from submitting when searching with jQuery

Solution is to apply the event.preventDefault() event method. Don't forget to pass the event through the function.

e.g.

jQuery("#webform-client-form-1148-1").submit(function(event){
   event.preventDefault();
});


remove input type="submit"

<input type="button" name="op" id="edit-submit-1" value="Submit"  class="form-submit" />

and the try this..

$('#edit-submit-1').click(function(){
        jQuery("#webform-client-form-1148-1").submit(function(){return false;});

});

if you don't want to submit your form at all then you can use unbind() or die()

you can use event.preventDefault(); too to prevent default action of form submit.

Hopes these alternative help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜