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.

Multiple Number Ranges

  1. Hi,

    Is there a way on a number field to apply multiple ranges?

    I'm attempting to set up a form which is nothing more than a simple "Validation" before you can proceed to the registration page. It ensures a member has a valid "Member number" before they can proceed to registration. Member numbers are 5 digits, but herein lies the rub; there are multiple ranges of member numbers. For example, the valid ranges are 10001 to 12000, then 20100 to 20200, 30000 to 30200, and finally 70000 through 70300.

    I attempted to get around this by adding four separate HTML blocks that show text saying, "The number is valid." depending on the value entered in the field (This wouldn't be a problem as it is impossible for all four number ranges to be satisfied at once; it would simply be one or the other.) If any single one of these messages were displayed, I wanted the submit button to show; however, apparently you can't use conditional logic based on HTML blocks.

    I also thought that perhaps I can have four submit buttons (All identical, one displays when one of the ranges is satisfied) however, you can't add more than one submit button to a form.

    The only feasible solution I thought of (And certainly not optimal, I will explain), is to have four number boxes and a label above each that describes "If your number is between 10001 and 12000, enter here." This essentially defeats the purpose.

    So I'm back to square one. I looked for add-ons that would feature advanced conditional logic, but no luck. To restate, I need a way for a user to enter a member number (Without being given instructions on what the acceptable range is) between multiple ranges, hit submit, and redirect to the registration page. Any help is appreciated.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  2. David Peralty

    You could create your own custom validation for a field and return an error if they are wrong, and let them submit fine if they are correct. You would use the hook gform_field_validation

    http://www.gravityhelp.com/documentation/page/Gform_field_validation

    Then you could test if the submitted number is in your ranges.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  3. Taking a look over, that seems to be what I'm looking for. I understand the logic, but I've never used a hook before; where would I input my custom validation hook? Wordpress's page.php, after identifying the page that houses the form?

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  4. David Peralty

    You would put it in your theme's functions.php file. http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  5. Great. Can I use this hook to return a true value for "is_valid" as opposed to a false one (In other words, write the hook based on what makes the validation "True", rather than what makes it false)?

    If that were the case, I can add an "else" that states if the conditions are not met, it is false, regardless.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  6. David Peralty

    This is a test for sending an error back. So what you would do is if field value is not between this range, or between this range or between this range or between this range, then return error.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  7. Thank you. This solved my problem.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  8. Thank you for the update.

    Posted 11 years ago on Monday April 1, 2013 | Permalink

This topic has been resolved and has been closed to new replies.