jQWidgets Forums
jQuery UI Widgets › Forums › Plugins › Validator, Drag & Drop, Sortable › Can validator prevent form from being submitted?
Tagged: jquery validator
This topic contains 3 replies, has 2 voices, and was last updated by Peter Stoev 9 years, 9 months ago.
-
Author
-
Hello,
I’m trying to use Validator in my PHP/CodeIgniter web app.
In my code, I have:
<form action=".../myclass/func" id="form" class="form" method="post" accept-charset="utf-8"> ... <label>Username:</label> <input type="text" id="user_id" name="user_id" /> <script type="text/javascript"> $(document).ready(function () { $("#user_id").jqxInput({ ... }); }); </script> ... <input type="submit" value="Login" id="loginButton" /> <script type="text/javascript"> $(document).ready(function () { $("#loginButton").jqxButton({ ... }); }); </script> ... </form> ... <script> $('#form').jqxValidator({rules: [{ input:'#user_id', rule:'required', ...}]}); $("#loginButton").click(function () { $('#form').jqxValidator('validate'); }); $("#form").on('validationError', function () { return false; // note: hope this will prevent the form from // being submitted but not working }); ... </script>
In my test, after the validation fails, it shows the error message next to the fields.
However, (I think) the form continues to be submitted.
So, right after the error message pops up, the screen gets updated to the next right away.
I add “return false” to the “validationError” event; however, it doesn’t stop the form from being submitted.
Is there anything I can do to prevent the form from being submitted when the validation fails, or am I missing anything?
Thank you!
Hi nimli,
On this page: http://www.jqwidgets.com/jquery-widgets-demo/demos/php/index.htm#demos/php/listbox.htm you will find demos which use jqxValidator along with Forms. It generally depends on how you submit your form. If you submit it on each click, then it does not matter whether you use validator or not. But you can submit it only if validation passes and that is demonstrated in the samples.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hello,
Thank you for getting back to me.
> “…On this page … will find demos which use jqxValidator along with Forms…”
Looking at the example in your link, I can see the demo usage of “jqxlistbox”. However, I don’t see “jqxvalidator.js” or validator functions at all… am I missing something?
Thank you.
Hi nimli,
The link points to PHP demos. See the demos please. Many of them use jqxValidator.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.