Support

Home Forums Event Espresso Premium form validation

form validation

Posted: January 14, 2013 at 1:25 pm

Viewing 6 reply threads


Adelaide

January 14, 2013 at 1:25 pm

Is there a way to validate form input format, like is done for email address? Would like to validate phone numbers for at least all numeric. And on the same note, I’d like to do a dropdown for State that has all the state abbreviations and an ‘other’ option for non-US states and provinces.


Josh

  • Support Staff

January 17, 2013 at 9:59 am

Hi Adelaide,

Numeric validation can be done for the phone number field. One way to add this would be by adding a rule to the validation.js script found in event-espresso/scripts. Here is some example code:

$jaer = jQuery.noConflict();
    jQuery(document).ready(function($jaer) {
    jQuery(function(){
        //Registration form validation


        jQuery('#registration_form').validate({
            rules: {
                phone: {
                    required: true,
                    number: true
                }
            }
        });
    });
});

The State question is set to be a text question by default, so it would take some hacking to make it into a dropdown type question, which isn’t something we can support at this time. I’ll note this as a feature request where that field could be changed to allow for a dropdown option.


Adelaide

January 17, 2013 at 1:03 pm

Thank you Josh. That worked, but I changed number: true to phoneUS: true, hoping that it would allow or require parens around the area code and hyphen between first 3 and last 4 digits. It doesn’t.

A related question: will validate.js be replaced the next time there’s a software update?


Josh

  • Support Staff

January 17, 2013 at 2:12 pm

Hi Adelaide,

Yes, anything in the core plugin will get replaced in an update. What you can do is de-register the standard validation.js file and add the validation script to your own custom JavaScript file in your theme or custom plugin.

Thre is a WordPress function that you can use to to this: wp_deregister_script(). You’ll need to specify which script to remove by it’s name or handle. The handle for the validation script is validation. Here is some example code that could be used in a theme functions.php file or a custom plugin:

add_action( 'wp_print_scripts', 'my_deregister_eevalidation', 100 );

function my_deregister_eevalidation() {
    wp_deregister_script( 'validation' );
}

Then you can copy your customized validation script to a JavaScript that you already are using, or one set aside just for this purpose.


Adelaide

January 18, 2013 at 2:07 pm

Thank you!


Josh

  • Support Staff

January 18, 2013 at 2:32 pm

You’re welcome. I looked into that phoneUS option, and it looks like that isn’t included with the core validate plugin. So some additional code would need to be added to add that method. Here are a few references that may help:

http://docs.jquery.com/Plugins/Validation/CustomMethods/phoneUS

http://blog.lysender.com/2012/08/custom-us-phone-validator-with-jquery-validate-plugin/


Adelaide

January 21, 2013 at 7:51 am

That did the trick.. Thanks again.

Viewing 6 reply threads

The support post ‘form validation’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso