Solved

Trying to use jquery validation plugin on click, kind of works but continues on

Posted on 2013-06-03
2
333 Views
Last Modified: 2013-06-04
Hi,
I have a form that when I submit as shown below, the subject rule error shows for a brief second before it continues on with the submission. It doesn't stop the form from submitting. Can't figure out what to do...bit extra code in there for the CKEditor. No errors showing up in firebug, all works, submits, except if I intentionally leave the subject field blank, I see the error for a brief second and it keeps going.

<script type="text/javascript">

$( "#save-exit" ).live('click', function() {

	$("#emailsettings").validate({
		rules: {
		subject: {required: true}
		}
		});
        
        window.onbeforeunload = 'NULL';
        
        var content = {
            html_HEAD:CKEDITOR.instances.html_HEAD.getData(),
            html_MAIN:CKEDITOR.instances.html_MAIN.getData(),
            title: $('input[name=title]').val(),
            subject: $('input[name=subject]').val(),
            from_name: $('input[name=from_name]').val(),
            from_email: $('input[name=from_email]').val(),
            scheduled: $('input[name=scheduled]').val(),
            id: $("#id").val(),
            cid: $("#cid").val(),
            template: $("select[name='templates']").val(),
            sponsor_id: $("select[name='sponsor']").val(),
        }

        $.ajax({
            url: 'email/save',
            type: 'post',
            success: function (data) {
            window.location.href = '/app/email';
            },
            data: content
        });
    });
   
</script>

Open in new window

0
Comment
Question by:tjyoung
2 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 39217487
when you submit and see the error msg briefly :
it's validating but you haven't told it to submit only if validation gives a thumbs up ...

      
if($("#emailsettings").validate().form()) {      
      $.ajax({
            url: 'email/save',
            type: 'post',
            data: content,
            success: function (data) {
                  window.location.href = '/app/email';
            }            
      });
}      
return false;      

stick this into your code (replace your existing ajax) and it should be good to go ...
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 39218516
Perfect. Thanks for clarifying!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now