Solved

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

Posted on 2013-06-03
2
348 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how can i extend ? 2 41
jquery auto complete 11 15
Getting selected value of a dropdown with jquery 7 31
Simple Total function not working 8 30
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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 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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now