Skip to:
Content

BuddyPress.org

Changeset 3650 for trunk/bp-xprofile.php


Ignore:
Timestamp:
01/04/2011 12:33:48 PM (16 years ago)
Author:
boonebgorges
Message:

Ensures that datebox profile field types have their values displayed properly on the profile edit screen. Cleans us bp_get_the_profile_field_options() and reworks the way that default values work in the case of multiselect and checkbox fields. Fixes #2947. Props r-a-y, cnorris23

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile.php

    r3643 r3650  
    226226                        if ( !isset( $_POST['field_' . $field_id] ) ) {
    227227
    228                                 if ( is_numeric( $_POST['field_' . $field_id . '_day'] ) ) {
     228                                if ( !empty( $_POST['field_' . $field_id . '_day'] ) && is_numeric( $_POST['field_' . $field_id . '_day'] ) ) {
    229229                                        /* Concatenate the values. */
    230230                                        $date_value = $_POST['field_' . $field_id . '_day'] . ' ' .
     
    251251                        /* Now we've checked for required fields, lets save the values. */
    252252                        foreach ( (array)$posted_field_ids as $field_id ) {
    253                                 if ( !xprofile_set_field_data( $field_id, $bp->displayed_user->id, $_POST['field_' . $field_id], $is_required[$field_id] ) )
     253                               
     254                                // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
     255                                if ( empty( $_POST['field_' . $field_id] ) )
     256                                        $value = array();
     257                                else
     258                                        $value = $_POST['field_' . $field_id];
     259                                       
     260                                if ( !xprofile_set_field_data( $field_id, $bp->displayed_user->id, $value, $is_required[$field_id] ) )
    254261                                        $errors = true;
    255262                                else
    256                                         do_action( 'xprofile_profile_field_data_updated', $field_id, $_POST['field_' . $field_id] );
     263                                        do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
    257264                        }
    258265
     
    668675                return false;
    669676
    670         /* If the value is empty, then delete any field data that exists */
    671         if ( empty( $value ) ) {
     677        $field = new BP_XProfile_Field( $field_id );
     678
     679        // If the value is empty, then delete any field data that exists, unless the field is of a
     680        // type where null values are semantically meaningful
     681        if ( empty( $value ) && 'checkbox' != $field->type && 'multiselectbox' != $field->type ) {
    672682                xprofile_delete_field_data( $field_id, $user_id );
    673683                return true;
    674684        }
    675 
    676         $field = new BP_XProfile_Field( $field_id );
    677685
    678686        /* Check the value is an acceptable value */
     
    688696                                        unset( $value[$i] );
    689697                        }
    690 
    691                         if ( empty( $value ) )
    692                                 return false;
    693698
    694699                        /* Reset the keys by merging with an empty array */
Note: See TracChangeset for help on using the changeset viewer.