[buddypress-trac] [BuddyPress Trac] #5738: Required xprofile fields errors management in members/single/profile/edit.php

buddypress-trac noreply at wordpress.org
Tue Jul 8 10:35:00 UTC 2014


#5738: Required xprofile fields errors management in
members/single/profile/edit.php
-------------------------+-----------------------------
 Reporter:  WCUADD       |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  XProfile     |    Version:
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 When a required xprofile field is missing in the register/sign up process,
 then an error message ("missing field") is returned associated with the
 specific field thanks to the call to
 `bp_get_the_profile_field_errors_action()` in the
 `$field_type->edit_field_html()`.

 This is not the case in the update profile process, only a global error
 message is shown. '''Could this be standardize reproducing the required
 xprofile fields errors management in the sign up process ?'''

 The error is catched during the sign up validation in
 `bp_core_screen_signup()` (`bp-members-screens.php`) and the error
 caracterised in line 142

 {{{
 add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo
 apply_filters(\'bp_members_signup_error_message\', "<div class=\"error\">"
 . stripslashes( \'' . addslashes( $error_message ) . '\' ) . "</div>" );'
 ) );
 }}}

 The same errors process management should occur when updating profile in
 `members/single/profile/edit.php`.

 The errors in updating profile are catched in
 `xprofile_screen_edit_profile()` (`bp-xprofile-screens.php`) on line 88.


 {{{
 $is_required[$field_id] = xprofile_check_is_required_field( $field_id );
 if ( $is_required[$field_id] && empty( $_POST['field_' . $field_id] ) ) {
    $errors = true;
 }
 }}}

 but only a global message is emitted on line 96 same file

 {{{
 bp_core_add_message( __( 'Please make sure you fill in all required fields
 in this profile field group before saving.', 'buddypress' ), 'error' );
 }}}

 There is no error message associated to the particular missing field, as
 for the sign up process. This could be dealt very easily by modifying the
 line 88 as follows for example :


 {{{
 if ( xprofile_check_is_required_field( $field_id ) && empty(
 $_POST['field_' . $field_id] ) && $_POST['field_' . $field_id] !== '0'){
     $errors = true;
     add_action( 'bp_field_'.$field_id.'_errors', 'mandatory_field_error'
 );
 }
 }}}

 where `mandatory_field_error()` could be a function defined as follows
 (better with a filter). This function could be factorised with the one in
 `bp_core_screen_signup()` (line 142 `bp-members-screens.php`) which was
 created only there, but could be used elsewhere as proposed in this
 ticket.

 {{{
 function mandatory_field_error( ) {
     $message = '<div class="error">'.__( 'This is a required field',
 'buddypress' ).'</div>';
     echo (apply_filters( 'mandatory_field_error', $message ))
     return;
 }
 }}}

 Please note the correction in the test

 {{{
 if ( xprofile_check_is_required_field( $field_id ) && empty(
 $_POST['field_' . $field_id] ) && $_POST['field_' . $field_id] !== '0')
 }}}
 relevant to [ticket
 5731][https://buddypress.trac.wordpress.org/ticket/5731#comment:9]

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5738>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list