www.webdeveloper.com
Results 1 to 9 of 9

Thread: Handler and form submission

  1. #1
    Join Date
    Sep 2005
    Posts
    1,626

    Question Handler and form submission

    I use
    http://bassistance.de/jquery-plugins...in-validation/

    When validation is correct user can refresh page where is confirmation message. As I like to use handler to avoid submitting form values, need help how to do in the correct way.

    Example is like:
    PHP Code:
            // specifying a submitHandler this will submit the form after we have validated ok
            
    submitHandler: function() {


                return 
    false// avoid the actual submit of the form.

            

    Is this possible using jQuery and handler?
    Last edited by toplisek; 02-07-2014 at 11:27 AM.

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,213
    Why bother when you can do it in straight JavaScript. If you want to know, please ask in the JavaScript Frameworks forum.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Aug 2012
    Location
    Greece
    Posts
    5
    Quote Originally Posted by toplisek View Post
    I use
    http://bassistance.de/jquery-plugins...in-validation/

    When validation is correct user can refresh page where is confirmation message. As I like to use handler to avoid submitting form values, need help how to do in the correct way.

    Example is like:
    PHP Code:
            // specifying a submitHandler this will submit the form after we have validated ok
            
    submitHandler: function() {


                return 
    false// avoid the actual submit of the form.

            

    Is this possible using jQuery and handler?
    Assuming you have set your validation, something like that:
    PHP Code:
    $("#someForm").validate({
            
    rules: {
                
    fieldName: { requiredtrueminlength},
                ...
            },
            ..
    messages other params
            
    }
        }); 
    your submit handler should not return false but prevent default, then check each field for validation.

    PHP Code:
            // specifying a submitHandler this will submit the form after we have validated ok
            
    submitHandler: function(e) {
               
    e.preventDefault();
               $(
    "#someForm input').each( function(){ 
                var testit = $("
    #someForm").validate().element(this);
            
    if (!testit) {
                 
    //if i am not mistaken, validation will add an invalid class there, if not you should mark it somehow for check after the loop
                 //handle invalid field
                  
    } else {
                    
    //handle valid fields
                  
    }
                 
    //here check for invalid class, whichever way you do it
                
    if (!$('#someForm .invalid').length) {
                $(
    "#someForm').submit();
              }

            } 
    most possibly i have some syntax errors as it's no tested.

  4. #4
    Join Date
    Sep 2005
    Posts
    1,626
    Will this prevent posting form when user refreshes browser?
    PHP Code:
    jQuery(document).ready(function() {
        
    // validate signup form on keyup and submit
        
    var validator jQuery("#validationForm").validate({
            
    rules: {
                
    firstname"required",  //Set the first name field to be a required Form

                
    email: {
                    
    requiredtrue,   //Set the e-mail field to be a required Form
                    
    emailtrue,      //Set the e-mail field to be validated as an e-mail address
                
    },

            },
            
    messages: {
                
    firstname"Enter your firstname",
                
    email: {
                    
    required"Please enter a valid email address",
                    
    minlength"Please enter a valid email address",
                }
            },

            
    // specifying a submitHandler this will submit the form after we have validated ok
    jQuery("#validationForm").validate({
      
    submitHandler: function(form) {
        
    form.submit();
      }
    });

        });


    }); 
    Last edited by toplisek; 02-08-2014 at 08:34 AM.

  5. #5
    Join Date
    Aug 2012
    Location
    Greece
    Posts
    5
    Yes, the preventDefault function does that as long as you pass the event object, i.e. someFunction(event) { event.preventDefault(); ) } will stop an element's default behaviour for the binded event.

    And especially in jQuery, it's much better to use that instead of return false;

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,213
    What part of ask in the JQuery forum don't people understand?
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Sep 2005
    Posts
    1,626
    I have tested and refreshed browser on confirmation page.
    Browser IE or Mozilla ask the following enclosed message.
    Even this message can not send any values inside form. Is this correct as I have received form values (they are not empty form values)
    Attached Images Attached Images
    Last edited by toplisek; 02-08-2014 at 12:57 PM.

  8. #8
    Join Date
    Sep 2005
    Posts
    1,626
    I receive an error like:

    Error: SyntaxError: missing : after property id
    Source Code:
    PHP Code:

            jQuery
    (".myformid").validate({ 
    What king of issue is with this?
    Can be used?
    .my_contacts-form1
    IE reports and error like:
    Object doesn't support this property or method
    jQuery(".my_contacts-form1").validate({
    Last edited by toplisek; 02-08-2014 at 02:00 PM.

  9. #9
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Quote Originally Posted by \\.\ View Post
    What part of ask in the JQuery forum don't people understand?
    here <gives him a big butcher's knife>
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles