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.

Custom regex validation for fields

  1. What I'd really, really, REALLY like to see is either of these two things:

    1) The ability to set a custom validation regex for any standard field OR
    2) The ability to create new custom field types (which would allow "normal" people to reuse custom fields we create).

    I'm actually pretty amazed that Gravity Forms doesn't just do either of these things out of the box - not even in the latest RC.

    Posted 12 years ago on Thursday October 27, 2011 | Permalink
  2. You can do regex validation using the gform_validation filter. The regex would go in your functions.php. If you mean via the form builder, that's something that has been discussed.

    You can create new custom field types using the gform_add_field_buttons filter. I wouldn't say it's non-complex, but it's certainly possible with Gravity Forms 1.5.3 or 1.6.

    Posted 12 years ago on Friday October 28, 2011 | Permalink
  3. I've checked out the gform_add_field_buttons - it's not complex at all, it's outright incomplete. There doesn't appear to be any other hooks or documentation for *defining* the field you've just created a button for.

    The gform_add_field_buttons filter merely adds a button for a field that does nothing. If I had time to reverse engineer the plugin, I'm sure I could figure it out, but since I'm pressed for time, I find I'm better off just building forms by hand, the old fashioned way.

    It seems to me that Gravity Forms just isn't very flexible OR developer-friendly.

    Posted 12 years ago on Friday October 28, 2011 | Permalink
  4. Danny
    Member

    Actually Gravity Forms does let you do this. Alex (from Gravity Forms) sent these instructions to me and they worked just fine.

    Following is a brief description on how to create a custom field type.

    1- Add your field type to the form editor toolbar using the following hook
    http://www.gravityhelp.com/documentation/page/Gform_add_field_buttons

    2- Render your field on the form by using the following hook
    http://www.gravityhelp.com/documentation/page/Gform_field_input

    3- Validate user entered input and return a validation error when appropriate, using the following hook
    http://www.gravityhelp.com/documentation/page/Gform_field_validation (requires v. 1.6 which is still in beta)
    OR
    http://www.gravityhelp.com/documentation/page/Gform_validation

    4- If your field type requires special client side scripts, use the following hook to enqueue them
    http://www.gravityhelp.com/documentation/page/Gform_enqueue_scripts

    5- If your field type requires additional settings, you can add them using the following hooks
    Advanced Tab Settings
    http://www.gravityhelp.com/documentation/page/Gform_field_advanced_settings

    Standard Tab Settings
    http://www.gravityhelp.com/documentation/page/Gform_field_standard_settings

    Posted 12 years ago on Monday November 7, 2011 | Permalink
  5. Thanks for the update Danny.

    Posted 12 years ago on Tuesday November 8, 2011 | Permalink
  6. Thanks, Danny. That's actually very helpful.

    Someone needs to put your post in the Wiki. I'm sure there's others out there who will benefit.

    Posted 12 years ago on Tuesday November 8, 2011 | Permalink