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.

Field for offer code

  1. veryc
    Member

    Hi, is there a field I can use for an offer code. The code will be an alphanumeric string. Ideally I want to verify the code is valid before submitting form.

    Thanks.

    Posted 13 years ago on Tuesday February 8, 2011 | Permalink
  2. There is no built in "offer code" functionality. It's possible to implement, but you would have to use a standard text input field and then use the gform_validation hook to write your own custom validation to validate this field. I'm not sure what your PHP and WordPress development skill level is... but here is an example of the gform_validation hook.

    <?php
    add_filter('gform_validation', '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;
    }
    ?>

    The gform_validation hook allows you to specific custom validation for a field. So you could use it to validate a string against a database table containing values, or virtually anything you want to do from a validation standpoint as long as you know how to write the code.

    Posted 13 years ago on Tuesday February 8, 2011 | Permalink