Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/05/2008 12:15:13 AM (18 years ago)
Author:
apeatling
Message:

Fixed the validation of dates on signup form, as well as callback of values. Dates entered on the signup form now save correctly and pass through to an activated account profile.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp_xprofile/bp_xprofile.signup.php

    r6 r10  
    9090                        {
    9191                                $_POST['blog_id'] = $_POST['user_name'];
    92                                 $_POST['blog_title'] = $_POST['field_1']; // The core 'Full Name' field.
     92                                $_POST['blog_title'] = $_POST['field_1']; // The core name fields.
    9393
    9494                                $counter = 0;
    9595                                $hasErrors = false;
     96                                $prev_field_id = 0;
    9697                                foreach($_POST as $key => $value)
    9798                                {
     
    100101                                                $field_id = explode("_", $key);
    101102                                                $field_id = $field_id[1];
     103                                                $field_type = BP_XProfile_Field::get_type($field_id);
    102104                                               
    103                                                 $field = new BP_XProfile_Field($field_id);
    104                                                
    105                                                 $bp_xprofile_callback[$counter] = array(
    106                                                         "field_id" => $field_id,
    107                                                         "value" => $value
    108                                                 );
    109                                                
    110                                                 if($field->is_required && $_POST[$key] == '')
    111                                                 {
    112                                                         $bp_xprofile_callback[$counter]["error_msg"] = $field->name . ' cannot be left blank.';
    113                                                         $hasErrors = true;
     105                                                // Need to check if the previous field had
     106                                                // the same ID, as to not validate individual
     107                                                // day/month/year dropdowns individually.
     108                                                if($prev_field_id != $field_id) {
     109                                                        $field = new BP_XProfile_Field($field_id);
     110                                                       
     111                                                        if($field_type == "datebox") {
     112                                                                $value = strtotime($_POST['field_' . $field_id . '_day'] . " " .
     113                                                                             $_POST['field_' . $field_id . '_month'] . " " .
     114                                                                             $_POST['field_' . $field_id . '_year']);
     115                                                        }
     116                                                       
     117                                                        $bp_xprofile_callback[$counter] = array(
     118                                                                "field_id" => $field->id,
     119                                                                "type" => $field->type,
     120                                                                "value" => $value
     121                                                        );
     122                                                       
     123                                                        if($field->is_required && $_POST[$key] == '')
     124                                                        {
     125                                                                $bp_xprofile_callback[$counter]["error_msg"] = $field->name . ' cannot be left blank.';
     126                                                                $hasErrors = true;
     127                                                        }       
     128                                                       
     129                                                        $counter++;
    114130                                                }
    115131                                               
    116                                                 $counter++;
     132                                                $prev_field_id = $field_id;
    117133                                        }
    118134                                }
     
    122138                               
    123139                                if ( $errors->get_error_code() || $hasErrors ) {
     140
    124141                                        signup_user($user_name, $user_email, $errors);
    125142                                       
     
    145162                                        for($i=0; $i<count($bp_xprofile_callback); $i++)
    146163                                        {
    147                                                 $meta['field_' . $bp_xprofile_callback[$i]['field_id']] = $bp_xprofile_callback[$i]['value'];
     164                                                $meta['field_' . $bp_xprofile_callback[$i]['field_id']] .= $bp_xprofile_callback[$i]['value'];
    148165                                        }
    149166                                       
    150167                                        $meta['xprofile_field_ids'] = $_POST['xprofile_ids'];
    151168                                        $meta = apply_filters( "add_signup_meta", $meta );
    152                                        
     169
    153170                                        wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
    154171                                        confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
     
    210227        global $wpdb, $wpmuBaseTablePrefix, $profile_picture_path;
    211228       
     229        // Extract signup meta fields to fill out profile
    212230        $field_ids = get_blog_option($blog_id, 'xprofile_field_ids');
    213231        $field_ids = explode(",", $field_ids);
    214        
     232               
     233        // Get the new user ID.
    215234        $sql = "SELECT u.ID from " . $wpmuBaseTablePrefix . "users u,
    216235                        " . $wpmuBaseTablePrefix . "usermeta um
     
    218237                        AND um.meta_key = 'primary_blog'
    219238                        AND um.meta_value = " . $blog_id;
    220 
     239                       
    221240        $user_id = $wpdb->get_var($sql);
    222        
     241
     242        // Loop through each bit of profile data and save it to profile.
    223243        for($i=0; $i<count($field_ids); $i++)
    224244        {
     
    228248                       
    229249                        $field = new BP_XProfile_ProfileData();
    230                        
    231250                        $field->user_id = $user_id;
    232251                        $field->value = $field_value;
    233252                        $field->field_id = $field_ids[$i];
    234                         $field->last_updated = time();                 
    235 
     253                        $field->last_updated = time(); 
     254       
    236255                        $field->save();
    237256                        delete_blog_option($blog_id, 'field_' . $field_ids[$i]);
     
    240259        delete_blog_option($blog_id, 'xprofile_field_ids');     
    241260       
     261        // Set up profile pictures and create a directory to store them for the user.
    242262        $profile_picture_path = trim(get_blog_option($blog_id, 'upload_path')) . '/profilepics';
    243263
     
    260280               
    261281        }
     282
    262283}
    263284
Note: See TracChangeset for help on using the changeset viewer.