Problem adding custom user registration fields
-
I’ve got a custom field, which I’ve successfully implemented in the profile editor and it retrieves a list of options from a database and displays the user’s current setting and allows you to save a new setting. So that’s all fine. My problem is in trying to add that field to the user registration page. I’ve followed the instructions in the Codex and in several tutorials, using the three hooks they say I need, but I’m seeing no change on the user registration page at all.
I’m adding the following code into the theme’s functions.php (just under the code I added to display the new field on the profile editor page).
I haven’t finished adding customization code, so I know it isn’t 100% working yet, but I can’t even get it to display the field. Anyone have any idea what I might be doing wrong here?
//Custom Registration Form Fields //1. Add a new form element... add_action( 'register_form', 'et_register_form' ); function et_register_form() { //$location = ( ! empty( $_POST['location'] ) ) ? trim( $_POST['location'] ) : ''; ?> <p> <label for="location">Location<br /> <input type="text" name="location" id="location" class="input" value="baytown" size="25" /> </label> </p> <?php } //2. Add validation. In this case, we make sure location is required. add_filter( 'registration_errors', 'et_registration_errors', 10, 3 ); function et_registration_errors( $errors, $sanitized_user_login, $user_email ) { if ( empty( $_POST['location'] ) || ! empty( $_POST['location'] ) && trim( $_POST['location'] ) == '' ) { $errors->add( 'location_error', 'You must include a location!' ); } return $errors; } //3. Finally, save our extra registration user meta. add_action( 'user_register', 'et_user_register' ); function et_user_register( $user_id ) { if ( ! empty( $_POST['location'] ) ) { update_user_meta( $user_id, 'location', trim( $_POST['location'] ) ); } }
- The topic ‘Problem adding custom user registration fields’ is closed to new replies.