By srdrupal on
First of all, I apologize if I have put this topic in wrong category, but I am new to Drupal and this is my first post.
Does anyone know how can we stop form from submitting and do client-side validation? We need to be able to have JavaScript confirmation before submitting, but currently form does submit either we have chosen YES or CANCEL on confirm. Thans in advance.
Comments
Have your javascript return false
Your javascript submit handler should return false on validation errors (or user clicking cancel).
The problem's not in our JS handler
Hello and thanks for your answer.
But, we have done that, we returned false from our submit handler and still it didn't work, Drupal submits our form. Is there anything else that might be a solution to our problem? Thanks a lot!
Drupal only submits the form if the browser does
So without knowing your code it hard to even know where to start. I would start by using firebug (and extension to firefox) and see what the validation code is doing. Also, are you attaching the submit handler to the form or the button? (I am pretty sure you want it attached to the form).
want to add js confirmation pop up
say I add to the submit button
$form['submit']['#attributes'] = array('onclick'=>'confirm("testing...")';
How do I stop the from from submitting if confirm returns false???? It seems to go through even it I click cancel.
~fayola
--------
http://www.fayola.net
Try onsubmit instead of onclick
I think you need to onsubmit in order to abort the form being submitted.
no luck with onsubmit
tried:
$form['submit']['#attributes'] = array('onsubmit' => 'confirm("testing...")');
and
$form['#attributes'] = array('onsubmit' => 'confirm("testing...")');
still no luck.
~fayola
--------
http://www.fayola.net
so I guess no one has any
so I guess no one has any ideas?
I don't want to have to add a new module (javascript validation one it think) as this is a production site I'm woring on and I want to to be as minimal as possible
~fayola
--------
http://www.fayola.net
can you pastebin the html?
Can you pastebin the html result of your form? Ie, show us what Drupal is producing?
Dave
My site: http://www.unitorganizer.com/myblog
here is how you can do this
in your javascript function return false if it fails validation.
thanks for the suggestion, I
thanks for the suggestion, I can see this working, but I had already came up with an alternative. I will keep this in mind for the future.
~fayola
--------
http://www.fayola.net
Hey, can you mention what
Hey, can you mention what the alternative is?