• Resolved jakus

    (@jakus)


    Hey there,

    Just started using this plugin, the flexibility is great so far!

    I was wondering if you had any recommended methods for implementing custom validation, either client or server side?

    I know native browser validation is included, but I’d like to be able to implement a more uniform style and also potentially stop malicious content being submitted server-side (once client-side validation is cleared).

    Cheers,
    J

Viewing 4 replies - 1 through 4 (of 4 total)
  • Lap

    (@lapzor)

    We have a huge load of features that we will add in the future, custom validation integration being one on the wishlist as well.

    For now you could go with something like https://jqueryvalidation.org (or any other variant of that), but it’s somewhat unrelated to our plugin at this point.

    Hey Jakus,

    To add to what my colleague said, here’s what the plugin already does (server-side).

    – It checks for any fields marked as “required” in your form content.
    – It validates all “email” fields.

    You can implement additional validation by hooking into the hf_validate_form filter hook.

    Here’s an example:

    
    add_filter( 'hf_validate_form', function( $error_code, $form, $data ) {
    
    	if( $data['SOME_FIELD'] !== 'value we want' ) {
    		$error_code = 'error'; // This shows the general error message right now.
    	}
    
    	return $error_code;
    }, 10, 3 );
    

    Right now you can return any non-empty string to raise an error.

    Hope that clarifies a little. If you have any ideas on how to further improve upon this, let us know please.

    Thread Starter jakus

    (@jakus)

    This is great info! Thanks guys.

    I probably didn’t dig into the documentation as much as I could have.

    I’ll let you know if I think of anything else that could be implemented.

    Cheers.

    • This reply was modified 7 years ago by jakus.

    Hey Jakus,

    No worries, the knowledge base is still pretty new so definitely lots of room to improve there for us. I just added an article on custom form validation to it.

    Cheers!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Validation’ is closed to new replies.