PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Force postal code format

  1. dfrayne
    Member

    Is it possible to force the postal code format, as in the phone format? ie. A1A 1A1. I would like to have it all caps, with a space between or else it comes up as invalid. If not, I guess I can put the e.g. in the "Description" and hope people follow it. Thanks.

    Posted 9 years ago on Wednesday March 16, 2011 | Permalink
  2. Yes, it is possible via the gform_validation hook and custom code. You would have to be sure your field description explains the correct format. We will be launching all new documentation (and site) next week, and the gform_validation hook will have a better example available for users that want to use it to implement custom validation.

    Posted 9 years ago on Wednesday March 16, 2011 | Permalink
  3. dfrayne
    Member

    Thanks Carl. Is that hook in the current documentation? Our contests launches this Saturday. Thanks.

    Posted 9 years ago on Wednesday March 16, 2011 | Permalink
  4. The hook is not in the current documentation.

    The hook is the gform_validation hook. Here is an example of it's usage:

    <?php
    add_filter('gform_validation_YOURFORMID', 'custom_validation');
    function custom_validation($validation_result){
    
    // set the form validation to false
    $validation_result["is_valid"] = false;
    $form = $validation_result["form"];
    
    // specify the first field to be invalid and provide custom validation message
    $form["fields"][0]["failed_validation"] = true;
    $form["fields"][0]["validation_message"] = "This field is invalid!";
    
    // update the form in the validation result with the form object you modified
    $validation_result["form"] = $form;
    
    return $validation_result;
    
    }
    ?>

    You would have to know PHP and hook/filter usage in order to put it to use. That example just sets a field to invalid, you would have to add code above that to check the field value and decide if you wanted to set it to invalid or not.

    Posted 9 years ago on Wednesday March 16, 2011 | Permalink