Using Gravity Forms ‘gform_rfc_url_validation’ PHP action

The gform_rfc_url_validation filter enables and disables RFC URL validation in Gravity Forms.

Usage

add_filter('gform_rfc_url_validation', 'your_custom_function', 10, 1);

Parameters

  • $validate_rfc (bool): The default value is true. Set to false to disable RFC URL validation.

More information

See Gravity Forms Docs: gform_rfc_url_validation

Examples

Disable RFC URL validation

Disable RFC URL validation using the __return_false function.

add_filter('gform_rfc_url_validation', '__return_false', 10, 1);

Custom function to disable RFC URL validation

Create a custom function to disable RFC URL validation and use it in the filter.

function disable_rfc_url_validation($validate_rfc) {
    // Disable RFC URL validation
    return false;
}
add_filter('gform_rfc_url_validation', 'disable_rfc_url_validation', 10, 1);

Disable RFC URL validation for a specific form

Disable RFC URL validation only for a specific form by checking the form ID.

function disable_rfc_url_validation_for_form($validate_rfc) {
    // Get the current form
    $form = GFFormsModel::get_current_form();

    // Check if the form ID is 5
    if ($form['id'] == 5) {
        // Disable RFC URL validation for form ID 5
        return false;
    }

    // Keep the default validation for other forms
    return $validate_rfc;
}
add_filter('gform_rfc_url_validation', 'disable_rfc_url_validation_for_form', 10, 1);

Enable RFC URL validation only on specific fields

Enable RFC URL validation only for specific fields by checking the field ID.

function enable_rfc_url_validation_for_field($validate_rfc) {
    // Get the current field
    $field = GFFormsModel::get_current_field();

    // Check if the field ID is 10
    if ($field['id'] == 10) {
        // Enable RFC URL validation for field ID 10
        return true;
    }

    // Disable the default validation for other fields
    return false;
}
add_filter('gform_rfc_url_validation', 'enable_rfc_url_validation_for_field', 10, 1);

Conditional RFC URL validation

Enable or disable RFC URL validation based on a custom condition.

function conditional_rfc_url_validation($validate_rfc) {
    // Custom condition
    $user_role = 'editor';

    // Check if the current user has the 'editor' role
    if (current_user_can($user_role)) {
        // Enable RFC URL validation for users with the 'editor' role
        return true;
    }

    // Disable RFC URL validation for other users
    return false;
}
add_filter('gform_rfc_url_validation', 'conditional_rfc_url_validation', 10, 1);