WordPress.org

Ready to get started?Download WordPress

Forums

BuddyPress
Buddypress-Validate required registration field – but not with bp-profile-set (1 post)

  1. valuser
    Member
    Posted 2 years ago #

    bp 1.6.1 - child of bp default theme

    (i assume it can be done as captchas do it!)

    Have added a field to the registration form like this : (----> my problem is to validate this field)

    1) added these functions to functions.php

    /* Add sign-up field to BuddyPress sign-up array */

    function anewbp_custom_user_signup_field( $usermeta ) {
    	$usermeta['eyecolor'] = $_POST['eyecolor'];
    	return $usermeta;
    	}
    add_filter( 'bp_signup_usermeta', 'anewbp_custom_user_signup_field' );

    /* Add field_name from sign-up to usermeta on activation */

    function anewbp_user_activate_field( $signup ) {
    
    	update_usermeta( $signup['user_id'], 'eyecolor', $signup['meta']['eyecolor'] );
    	return $signup;
    }
    add_filter( 'bp_core_activate_account', 'anewbp_user_activate_field' );

    2) have added this to register.php at an appropriate place

    <label for="eyecolor"><?php _e( 'Last Name', 'buddypress' ); ?> <?php _e( '(required)', 'buddypress' ); ?></label>
    <input type="text" name="eyecolor" id="eyecolor" value="" />

    So far so good.

    However I need this to be a REQUIRED field and am having problems !!

    What have I tried ?

    a)

    function anewbp_check_validation(){
    	global $bp;
    	$anewbp_custom_user_signup_field_txt = $_POST['eyecolor'];
    
    	if (empty($anewbp_custom_user_signup_field_txt) || $anewbp_custom_user_signup_field_txt == '') {
    		$bp->signup->errors['anewbp_custom_user_signup_field'] = __('Please complete this field','buddypress');
    	}
    	return;
    }
    add_action('bp_signup_validate', ' anewbp_check_validation');

    AND

    <?php do_action( 'bp_anewbp_check_validation()' ) ?> in register.php

    b)

    function anewbp_check_validation(){
    	global $bp;
    	if (empty($_POST['eyecolor']) || $_POST['eyecolor'] == '') {
             $bp->signup->errors['eyecolor'] = __('Please complete this field','buddypress');
             return;
    }
    }
    add_action('bp_signup_validate', 'anewbp_check_validation');

    AND

    <?php do_action( 'bp_anewbp_check_validation()' ) ?> in register.php

    and other variations. --> none have worked

    Where I'm coming from? ---> Can follow and would be grateful for detailed instructions

    mainly a copy and paster but gradually getting an understanding of php.

    http://wordpress.org/extend/plugins/buddypress/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic