Skip to:
Content

BuddyPress.org

Ticket #3233: xprofil-select-multiselect-field-patch.patch

File xprofil-select-multiselect-field-patch.patch, 2.6 KB (added by sbrajesh, 14 years ago)
  • bp-xprofile/bp-xprofile-template.php

     
    407407                        $field = new BP_XProfile_Field( $field->id );
    408408
    409409                $options = $field->get_children();
    410 
     410             
    411411                // Setup some defaults
    412412                $html     = '';
    413413                $selected = '';
     
    417417                        case 'selectbox': case 'multiselectbox':
    418418                                if ( 'multiselectbox' != $field->type )
    419419                                        $html .= '<option value="">--------</option>';
    420 
     420                               //find the values selected by user
     421                                $user_selected_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) );
     422                                       
    421423                                for ( $k = 0; $k < count($options); $k++ ) {
    422                                         $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id ) );
    423                                         $option_values = (array) $original_option_values;
     424                                        $option_values = (array) $user_selected_values;
    424425
    425                                         // Check for updated posted values, but errors preventing them from being saved first time
    426                                         foreach( $option_values as $i => $option_value ) {
    427                                                 if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) {
    428                                                         if ( !empty( $_POST['field_' . $field->id] ) )
    429                                                                 $option_values[$i] = $_POST['field_' . $field->id];
    430                                                 }
    431                                         }
    432 
     426                                       
    433427                                        $selected = '';
    434428                                       
    435429                                        // Run the allowed option name through the before_save
    436430                                        // filter, so we'll be sure to get a match
    437                                         $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
     431                                        $current_option = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    438432                                       
    439433                                        // First, check to see whether the user-entered value
    440434                                        // matches
    441                                         if ( in_array( $allowed_options, (array) $option_values ) )
     435                                        if ( in_array( $current_option, $option_values ) )
    442436                                                $selected = ' selected="selected"';
    443437
    444438                                        // Then, if the user has not provided a value, check for
    445439                                        // defaults
    446                                         if ( !is_array( $original_option_values ) && empty( $option_values ) & $options[$k]->is_default_option )
     440                                        if ( !is_array( $user_selected_values ) && empty( $user_selected_values ) & $options[$k]->is_default_option )
    447441                                                $selected = ' selected="selected"';
    448442
    449443                                        $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k] );