bookmark_bordergform_user_registration_validation

Description

This filter is used to validate submissions that have a User Registration feed attached to the submitted form. It passes several useful variables that make validating submissions dependent on a User Registration feed easier.

This filter is particularly useful if you are adding custom settings/meta to the User Registration feed using the gform_user_registration_add_option_section or gform_user_registration_add_option_group hooks and need to validate the submitted entry based on these settings/meta.

Usage

Applies to all forms

add_filter( 'gform_user_registration_validation', 'your_function_name', 10, 3 );

Parameters

  • $form

    The form currently being processed.

  • $feed Feed Object

    The Feed which is currently being processed.

  • $submitted_page integer

    The current page number (used to validate only the current page on multi-page forms)

Examples

This example uses the gform_user_registration_validation filter to validate the User Registration Add-on to add support for Multi-Site.

This example also uses a handy function available in the User Registration add-on which allows you to easily add validation errors to fields by ID: gf_user_registration()->add_validation_error().

add_action( 'gform_user_registration_validation', 'validate_multisite_submission', 10, 3 );
function validate_multisite_submission( $form, $feed, $submitted_page ) {
    global $path;

    $meta = rgar( $feed, 'meta' );

    // make sure multisite create site option is set
    if ( rgempty( 'createSite', $meta ) ) {
        return $form;
    }

    // $_POST to Entry
    $entry = GFFormsModel::get_current_lead();

    $site_address_field = GFFormsModel::get_field( $form, $meta['siteAddress'] );
    $site_address       = gf_user_registration()->get_meta_value( 'siteAddress', $meta, $form, $entry );

    $site_title_field = GFFormsModel::get_field( $form, $meta['siteTitle'] );
    $site_title       = gf_user_registration()->get_meta_value( 'siteTitle', $meta, $form, $entry );

    // get validation result for multi-site fields
    $validation_result = wpmu_validate_blog_signup( $site_address, $site_title, wp_get_current_user() );
    $error_msg         = false;

    // site address validation, only if on correct page
    if ( $site_address_field->pageNumber == $submitted_page ) {

        $error_msg = ( isset( $validation_result['errors']->errors['blogname'][0] ) ) ? $validation_result['errors']->errors['blogname'][0] : false;

        if ( $error_msg != false ) {
            $form = gf_user_registration()->add_validation_error( $meta['siteAddress'], $form, $error_msg );
        }
    }

    // site title validation, only if on correct page
    if ( $site_title_field->pageNumber == $submitted_page ) {

        $error_msg = ( isset( $validation_result['errors']->errors['blog_title'][0] ) ) ? $validation_result['errors']->errors['blog_title'][0] : false;

        if ( $error_msg != false ) {
            $form = gf_user_registration()->add_validation_error( $meta['siteTitle'], $form, $error_msg );
        }
    }

    return $form;
}

Source Code

$form = apply_filters( 'gform_user_registration_validation', $form, $feed, $submitted_page );

This filter is located in GF_User_Registration::validate() in class-gf-user-registration.php