Created
January 28, 2026 13:39
-
-
Save faisalahammad/0594adbdc940c86b3f604191c709b84f to your computer and use it in GitHub Desktop.
This simple PHP snippet allows users to enter URLs starting with "www." in the website field of Gravity Forms without requiring "https://". It modifies the validation logic to accept "www." by automatically prepending "https://" for validation. Ideal for WordPress developers looking to customize form URL validation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Allow URLs starting with "www." in Gravity Forms website field validation. | |
| * | |
| * This snippet enables users to enter URLs like "www.example.com" | |
| * without needing to type "https://". It prepends "https://" internally | |
| * for validation purposes. | |
| * | |
| * @author Faisal Ahammad <me@faisalahammad.com> | |
| */ | |
| add_filter( 'gform_field_validation', function( $result, $value, $form, $field ) { | |
| if ( $field->type !== 'website' ) { | |
| return $result; | |
| } | |
| if ( ! $result['is_valid'] && preg_match( '/^www\./i', trim( $value ) ) ) { | |
| $url_with_protocol = 'https://' . trim( $value ); | |
| if ( GFCommon::is_valid_url( $url_with_protocol ) ) { | |
| $result['is_valid'] = true; | |
| $result['message'] = ''; | |
| } | |
| } | |
| return $result; | |
| }, 10, 4 ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ticket: https://community.gravityforms.com/t/allowing-www-in-website-field/20028