BuddyDev

Search

Buddyoress user registration from not working

  • Participant
    Level: Initiated
    Posts: 4
    Bharat on #27579

    Hello Brijesh

    I’ve follow your article about create side bar register form and I’ve create my own short code and i’ve using that my short code on home page but registration page not working proper,
    Can you please help me ?

    1) Form data are not submitting in database and not create user and also not working validation .

    https://buddydev.com/show-buddypress-user-registration-form-everywhere-buddypress-site

    https://vp95wn7zb1g.c.updraftclone.com/

    Here is my code:

    <?php

    add_shortcode( ‘buddypress_register’, ‘new_register_home_page’);

    function new_register_home_page(){
    global $bp,$wpdb;
    $bp = buddypress();

    if( empty( $bp->signup->step ) ){

    $bp->signup->step=’request-details’;
    ?>
    <form action=”<?php echo bp_get_signup_page();?>” name=”signup_form” id=”signup_form” class=”standard-form newsss” method=”post” enctype=”multipart/form-data”>

    <?php if ( ‘registration-disabled’ == bp_get_current_signup_step() ) : ?>
    <?php do_action( ‘template_notices’ ); ?>
    <?php do_action( ‘bp_before_registration_disabled’ ); ?>

    <p><?php _e( ‘User registration is currently not allowed.’, ‘buddypress’ ); ?></p>

    <?php do_action( ‘bp_after_registration_disabled’ ); ?>
    <?php endif; // registration-disabled signup step ?>

    <?php if ( ‘request-details’ == bp_get_current_signup_step() ) : ?>

    <?php do_action( ‘template_notices’ ); ?>

    <p><?php _e( ‘Registering for this site is easy. Just fill in the fields below, and we\’ll get a new account set up for you in no time.’, ‘buddypress’ ); ?></p>

    <?php do_action( ‘bp_before_account_details_fields’ ); ?>

    <div class=”register-section” id=”basic-details-section”>

    <?php /***** Basic Account Details ******/ ?>

    <h4><?php _e( ‘Account Details’, ‘buddypress’ ); ?></h4>

    <label for=”signup_username”><?php _e( ‘Username’, ‘buddypress’ ); ?> <?php _e( ‘(required)’, ‘buddypress’ ); ?></label>
    <?php do_action( ‘bp_signup_username_errors’ ); ?>
    <input type=”text” name=”signup_username” id=”signup_username” value=”<?php bp_signup_username_value(); ?>” <?php bp_form_field_attributes( ‘username’ ); ?>/>

    <label for=”signup_email”><?php _e( ‘Email Address’, ‘buddypress’ ); ?> <?php _e( ‘(required)’, ‘buddypress’ ); ?></label>
    <?php do_action( ‘bp_signup_email_errors’ ); ?>
    <input type=”email” name=”signup_email” id=”signup_email” value=”<?php bp_signup_email_value(); ?>” <?php bp_form_field_attributes( ’email’ ); ?>/>

    <label for=”signup_password”><?php _e( ‘Choose a Password’, ‘buddypress’ ); ?> <?php _e( ‘(required)’, ‘buddypress’ ); ?></label>
    <?php do_action( ‘bp_signup_password_errors’ ); ?>
    <input type=”password” name=”signup_password” id=”signup_password” value=”” class=”password-entry” <?php bp_form_field_attributes( ‘password’ ); ?>/>
    <div id=”pass-strength-result”></div>

    <label for=”signup_password_confirm”><?php _e( ‘Confirm Password’, ‘buddypress’ ); ?> <?php _e( ‘(required)’, ‘buddypress’ ); ?></label>
    <?php do_action( ‘bp_signup_password_confirm_errors’ ); ?>
    <input type=”password” name=”signup_password_confirm” id=”signup_password_confirm” value=”” class=”password-entry-confirm” <?php bp_form_field_attributes( ‘password’ ); ?>/>

    <?php do_action( ‘bp_account_details_fields’ ); ?>

    </div><!– #basic-details-section –>

    <?php do_action( ‘bp_after_account_details_fields’ ); ?>

    <?php /***** Extra Profile Details ******/ ?>

    <?php if ( bp_is_active( ‘xprofile’ ) ) : ?>

    <?php do_action( ‘bp_before_signup_profile_fields’ ); ?>

    <div class=”register-section” id=”profile-details-section”>

    <h4><?php _e( ‘Profile Details’, ‘buddypress’ ); ?></h4>

    <?php /* Use the profile field loop to render input fields for the ‘base’ profile field group */ ?>
    <?php if ( bp_is_active( ‘xprofile’ ) ) : if ( bp_has_profile( array( ‘profile_group_id’ => 1, ‘fetch_field_data’ => false ) ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>

    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

    <div<?php bp_field_css_class( ‘editfield’ ); ?>>

    <?php
    $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() );
    $field_type->edit_field_html();

    do_action( ‘bp_custom_profile_edit_fields_pre_visibility’ );

    if ( bp_current_user_can( ‘bp_xprofile_change_field_visibility’ ) ) : ?>
    <p class=”field-visibility-settings-toggle” id=”field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>”>
    <?php printf( __( ‘This field can be seen by: <span class=”current-visibility-level”>%s</span>’, ‘buddypress’ ), bp_get_the_profile_field_visibility_level_label() ) ?> <?php _ex( ‘Change’, ‘Change profile field visibility level’, ‘buddypress’ ); ?>
    </p>

    <div class=”field-visibility-settings” id=”field-visibility-settings-<?php bp_the_profile_field_id() ?>”>
    <fieldset>
    <legend><?php _e( ‘Who can see this field?’, ‘buddypress’ ) ?></legend>

    <?php bp_profile_visibility_radio_buttons() ?>

    </fieldset>
    <?php _e( ‘Close’, ‘buddypress’ ) ?>

    </div>
    <?php else : ?>
    <p class=”field-visibility-settings-notoggle” id=”field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>”>
    <?php printf( __( ‘This field can be seen by: <span class=”current-visibility-level”>%s</span>’, ‘buddypress’ ), bp_get_the_profile_field_visibility_level_label() ) ?>
    </p>
    <?php endif ?>

    <?php do_action( ‘bp_custom_profile_edit_fields’ ); ?>

    <p class=”description”><?php bp_the_profile_field_description(); ?></p>

    </div>

    <?php endwhile; ?>

    <input type=”hidden” name=”signup_profile_field_ids” id=”signup_profile_field_ids” value=”<?php bp_the_profile_field_ids(); ?>” />

    <?php endwhile; endif; endif; ?>

    <?php do_action( ‘bp_signup_profile_fields’ ); ?>

    </div><!– #profile-details-section –>

    <?php do_action( ‘bp_after_signup_profile_fields’ ); ?>

    <?php endif; ?>

    <?php if ( bp_get_blog_signup_allowed() ) : ?>

    <?php do_action( ‘bp_before_blog_details_fields’ ); ?>

    <?php /***** Blog Creation Details ******/ ?>

    <div class=”register-section” id=”blog-details-section”>

    <h4><?php _e( ‘Blog Details’, ‘buddypress’ ); ?></h4>

    <p><input type=”checkbox” name=”signup_with_blog” id=”signup_with_blog” value=”1″<?php if ( (int) bp_get_signup_with_blog_value() ) : ?> checked=”checked”<?php endif; ?> /> <?php _e( ‘Yes, I\’d like to create a new site’, ‘buddypress’ ); ?></p>

    <div id=”blog-details”<?php if ( (int) bp_get_signup_with_blog_value() ) : ?>class=”show”<?php endif; ?>>

    <label for=”signup_blog_url”><?php _e( ‘Blog URL’, ‘buddypress’ ); ?> <?php _e( ‘(required)’, ‘buddypress’ ); ?></label>
    <?php do_action( ‘bp_signup_blog_url_errors’ ); ?>

    <?php if ( is_subdomain_install() ) : ?>
    http:// <input type=”text” name=”signup_blog_url” id=”signup_blog_url” value=”<?php bp_signup_blog_url_value(); ?>” /> .<?php bp_signup_subdomain_base(); ?>
    <?php else : ?>
    <?php echo home_url( ‘/’ ); ?> <input type=”text” name=”signup_blog_url” id=”signup_blog_url” value=”<?php bp_signup_blog_url_value(); ?>” />
    <?php endif; ?>

    <label for=”signup_blog_title”><?php _e( ‘Site Title’, ‘buddypress’ ); ?> <?php _e( ‘(required)’, ‘buddypress’ ); ?></label>
    <?php do_action( ‘bp_signup_blog_title_errors’ ); ?>
    <input type=”text” name=”signup_blog_title” id=”signup_blog_title” value=”<?php bp_signup_blog_title_value(); ?>” />

    <span class=”label”><?php _e( ‘I would like my site to appear in search engines, and in public listings around this network.’, ‘buddypress’ ); ?></span>
    <?php do_action( ‘bp_signup_blog_privacy_errors’ ); ?>

    <label><input type=”radio” name=”signup_blog_privacy” id=”signup_blog_privacy_public” value=”public”<?php if ( ‘public’ == bp_get_signup_blog_privacy_value() || !bp_get_signup_blog_privacy_value() ) : ?> checked=”checked”<?php endif; ?> /> <?php _e( ‘Yes’, ‘buddypress’ ); ?></label>
    <label><input type=”radio” name=”signup_blog_privacy” id=”signup_blog_privacy_private” value=”private”<?php if ( ‘private’ == bp_get_signup_blog_privacy_value() ) : ?> checked=”checked”<?php endif; ?> /> <?php _e( ‘No’, ‘buddypress’ ); ?></label>

    <?php do_action( ‘bp_blog_details_fields’ ); ?>

    </div>

    </div><!– #blog-details-section –>

    <?php do_action( ‘bp_after_blog_details_fields’ ); ?>

    <?php endif; ?>

    <?php do_action( ‘bp_before_registration_submit_buttons’ ); ?>

    <div class=”submit”>
    <input type=”submit” name=”signup_submit” id=”signup_submit” value=”<?php esc_attr_e( ‘Complete Sign Up’, ‘buddypress’ ); ?>” />
    </div>

    <?php do_action( ‘bp_after_registration_submit_buttons’ ); ?>

    <?php wp_nonce_field( ‘bp_new_signup’ ); ?>

    <?php endif; // request-details signup step ?>

    <?php if ( ‘completed-confirmation’ == bp_get_current_signup_step() ) : ?>

    <?php do_action( ‘template_notices’ ); ?>
    <?php do_action( ‘bp_before_registration_confirmed’ ); ?>

    <?php if ( bp_registration_needs_activation() ) : ?>
    <p><?php _e( ‘You have successfully created your account! To begin using this site you will need to activate your account via the email we have just sent to your address.’, ‘buddypress’ ); ?></p>
    <?php else : ?>
    <p><?php _e( ‘You have successfully created your account! Please log in using the username and password you have just created.’, ‘buddypress’ ); ?></p>
    <?php endif; ?>

    <?php do_action( ‘bp_after_registration_confirmed’ ); ?>

    <?php endif; // completed-confirmation signup step ?>

    <?php do_action( ‘bp_custom_signup_steps’ ); ?>

    </form>
    <?php
    }
    }

    add_action( ‘bp_core_screen_signup’, ‘buddydev_redirect_on_signup’ );

    /**
    * If the signup form is being processed, Redirect to the page where the signup form is
    *
    */
    function buddydev_redirect_on_signup() {

    // Bail if not a POST action
    if ( ‘POST’ !== strtoupper( $_SERVER[‘REQUEST_METHOD’] ) )
    return;

    $bp = buddypress();

    //only if bp signup object is set
    if( ! empty( $bp->signup ) ) {
    //save the signup object and submitted post data
    $_SESSION[‘buddydev_signup’] = $bp->signup;
    $_SESSION[‘buddydev_signup_fields’] = $_POST;

    }

    bp_core_redirect( wp_get_referer());

    }

    add_action( ‘bp_init’, ‘buddydev_process_signup_errors’ );

    function buddydev_process_signup_errors() {

    //we don’t need to process if the user is logged in
    if( is_user_logged_in() )
    return;

    //if session was not started by another code, let us begin the session
    if( ! session_id() )
    session_start ();

    //check if the current request
    if( ! empty( $_SESSION[‘buddydev_signup’] ) ) {

    $bp = buddypress();
    //restore the old signup object
    $bp->signup = $_SESSION[‘buddydev_signup’];

    //we are sure that it is our redirect from the buddydev_redirect_on_signup function, so we can safely replace the $_POST array
    if( isset( $bp->signup->errors ) && !empty( $bp->signup->errors ) )
    $_POST = $_SESSION[‘buddydev_signup_fields’];//we need to restore so that the signup form can show the old data

    $errors = array();

    if( isset( $bp->signup->errors ) )
    $errors = $bp->signup->errors;

    foreach ( (array) $errors as $fieldname => $error_message ) {

    add_action( ‘bp_’ . $fieldname . ‘_errors’, create_function( ”, ‘echo apply_filters(\’bp_members_signup_error_message\’, “<div class=\”error\”>” . stripslashes( \” . addslashes( $error_message ) . ‘\’ ) . “</div>” );’ ) );

    }
    //remove from session
    $_SESSION[‘buddydev_signup’] = null;
    $_SESSION[‘buddydev_signup_fields’] = null;
    }
    }

    ?>

  • Keymaster
    (BuddyDev Team)
    Posts: 24645
    Brajesh Singh on #27580

    Hi Bharat,
    Thank you for the question.

    I will need some time to check this code. Will get back to you in next couple of days.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved