Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/23/2014 01:42:48 PM (11 years ago)
Author:
boonebgorges
Message:

Introduce BP_XProfile_Field_Type::pre_validate_filter(), and use in URL field type

The pre_validate_filter() method allows field types to intercept field values,
before they are run through the is_valid() validation routine, and optionally
modify them.

BP_XProfile_Field_Type_URL uses this filter to silently add the 'http://'
protocol to submitted values before run through the validation regex (which
requires the protocol). The result is a smoother UX, as users are not required
to enter the protocol in order to have their field value saved.

To make it possible for protocol-less values to be submitted on the profile
edit form, the 'type' attribute of the URL field was changed from 'url' to
'text' (with a 'url' inputtype). With 'type=url', modern browsers require a
fully-qualified URL before allowing the form to be submitted.

Fixes #5501

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r8670 r8672  
    294294        return false;
    295295
    296     // Special-case support for integer 0 for the number field type
    297     if ( $is_required && ! is_integer( $value ) && $value !== '0' && ( empty( $value ) || ! is_array( $value ) && ! strlen( trim( $value ) ) ) ) {
    298         return false;
    299     }
    300 
    301296    $field          = new BP_XProfile_Field( $field_id );
    302297    $field_type     = BP_XProfile_Field::get_type( $field_id );
    303298    $field_type_obj = bp_xprofile_create_field_type( $field_type );
     299
     300    /**
     301     * Filter the raw submitted profile field value.
     302     *
     303     * Use this filter to modify the values submitted by users before
     304     * doing field-type-specific validation.
     305     *
     306     * @since BuddyPress (2.1.0)
     307     *
     308     * @param mixed $value Value passed to xprofile_set_field_data()
     309     * @param BP_XProfile_Field $field Field object.
     310     * @param BP_XProfile_Field_Type $field_type_obj Field type object.
     311     */
     312    $value = apply_filters( 'bp_xprofile_set_field_data_pre_validate', $value, $field, $field_type_obj );
     313
     314    // Special-case support for integer 0 for the number field type
     315    if ( $is_required && ! is_integer( $value ) && $value !== '0' && ( empty( $value ) || ! is_array( $value ) && ! strlen( trim( $value ) ) ) ) {
     316        return false;
     317    }
    304318
    305319    /**
Note: See TracChangeset for help on using the changeset viewer.