BuddyDev

Search

[Resolved] Buddypress conditional registration

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #44569

    Hello,

    I have a custom profile field for Privacy policy with the options (Accept) and (Reject)

    1. When users select option (Accept policy) they can register successfully
    2. But when user select the option (Reject policy) prevent user from registering and display error message (You are required to accept our privacy policy to complete registration)

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #44628

    Gentle reminder

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #44663

    Hello Tosin,

    Thank you for posting. BuddyPress does provide default functionality for privacy acceptance. It only checks a published privacy policy page. You can find Privacy Policy page settings under Settings > Privacy page in the dashboard. Please make sure your privacy page is published.

    Please give it a try.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #44664

    Please note that privacy policy acceptance works with the Nouveau template pack.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #44666

    Thanks for the feedback

    I specifically dont want to use the default functionality but a dropdown profile field instead.

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #44692

    Hi Tosin,
    If you are looking for code, It will be hardcoded to your field id.

    Please create a select field and share me the field id and the screenshot of the options(in the Edit Profile Field) section.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #44709

    Thank you Brajesh

    The group_id=5 & field_id=4448

    Screenshot at https://ibb.co/VtZTF3j

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #44769

    Hi tosin,
    Please use the following code

    
    
    // forces user to select a specific select field value on registration page.
    add_action( 'bp_signup_validate', function () {
    	$field_id       = 4448; // Your select field id.
    	$accepted_value = 'I accept'; // please change with the value you want to accept.
    
        if ( ! isset( $_POST[ 'field_' . $field_id ] ) ) {
    		return; //should never happen if the field is marked as required.
    	}
    
    	$selected_val = $_POST[ 'field_' . $field_id ];
    
    	if ( strtolower( $accepted_value ) !== strtolower( $selected_val ) ) {
    		buddypress()->signup->errors[ 'field_' . $field_id ] = __( 'This is a required field. You must accept.', 'buddypress' );
    	}
    
    } );
    

    please make sure to update the variable $accepted_value with the actual value which you have used for your selectbox.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #44773

    You are a genius Brajesh

    Thanks a lot

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #44786

    Is it ok to replicate this same code twice and use another field id.

    So there will be two similar code with different field id

    Thanks

The topic ‘ [Resolved] Buddypress conditional registration’ is closed to new replies.

This topic is: resolved