Help: New field on registration page.
-
Hi,
I am trying to create a new custom field on a registration page. The field asks for a code from another application and then it checks if the code is registered in a SQL table. The problem is that if that the error message for this field is not formatted the same as for the standard fields.
See this:
https://ibb.co/b2oqkp
I passed the same error message to the username box for comparison. But as you can see the last field (acctivation code) does not format correct, and is not showing red.
This is the code:add_action( 'bp_account_details_fields', 'mcreg_registration_form' ); function mcreg_registration_form() { $acctivationcode = ! empty( $_POST['signup_acctivation'] ) ? intval( $_POST['signup_acctivation'] ) : ''; ?> <div class="editfield signup_acctivation required-field visibility-public field_type_text" id="acctivation-field"> <label for="signup_acctivation"><?php _e( 'Acctivation code ', 'mcregister' ); ?><?php _e( '(required)', 'buddypress' ); ?><br/> </label> <?php /**https://github.com/buddypress/BuddyPress/blob/42837dd8e6e7fa37b1356f7fca6c3d5cded9c164/src/bp-templates/bp-legacy/buddypress/members/register.php * Fires and displays any member registration acctivation code errors. * value="<?php echo esc_attr( $acctivationcode ); ?>" */ do_action( 'bp_signup_acctivation_errors' ); ?> <input type="text" id="signup_acctivation" name="signup_acctivation" value="<?php echo esc_attr( $acctivationcode ); ?>" required /> </div> <?php } function mcreg_bp_registration_acctivation_validate( $errors ){ global $bp; //$error_message_incorrect = __( 'Please check the Acctivation code. It\'s not correct.', 'buddypress' ); $uuid = null; if(!empty($_POST['signup_acctivation'])){ try { $uuid = accode_to_uuid($_POST['signup_acctivation']); } catch (Exception $e) { //TODO: add database error message. $bp->signup->errors['signup_acctivation'] = __( 'Something went wrong when checking acctivation code', 'mcregister' ); } } if ($uuid==null ) { $bp->signup->errors['signup_acctivation'] = __( 'Please check the Acctivation code. It\'s not correct.', 'mcregister' ); $bp->signup->errors['signup_username'] = __( 'Please check the Acctivation code. It\'s not correct.', 'mcregister' ); //$bp->signup->errors['signup_acctivation'] = $error_message_incorrect; return; } $mcname = uuid_to_username($uuid); if(!$mcname==false){ $_POST['signup_username'] = $mcname; } //TODO: find a way to store UUID //$bp->signup->uuid = $uuid;; return; } //bp_signup_validate add_action( 'bp_signup_pre_validate', 'mcreg_bp_registration_acctivation_validate' );
I would also like to store the return code (called UUID) in the user profile if the registration is successful so its great if someone know how I can do this.
Last I would also like to hide the username (brukernavn) field as I will fill that problematically when I am doing the test, I am currently just overwriting it.
Thanks,
- You must be logged in to reply to this topic.