Theme my login extra fields not working? (1 post)

  1. lorembolo
    Posted 3 years ago #

    I'm usin the plugin Theme My Login for this website : http://artisti.bernardcousin.fr/ventes-privees/

    I would like to add FirstName and lastname to the register form. I have followed the instructins from the author: http://www.jfarthing.com/development/theme-my-login/adding-extra-registration-fields/

    I added this code to the file called "register-form.php" (a copy in my theme folder)

    	<label for="first_name<?php $template->the_instance(); ?>"><?php _e( 'First name', 'theme-my-login' ) ?></label>
    	<input type="text" name="first_name" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'first_name' ); ?>" size="20" tabindex="20" />
    	<label for="last_name<?php $template->the_instance(); ?>"><?php _e( 'Last name', 'theme-my-login' ) ?></label>
    	<input type="text" name="last_name" id="last_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'last_name' ); ?>" size="20" tabindex="20" />

    Then I created the file "theme-my-login-custom" in the root of plugin directory. This file has the followinf code :

    function tml_registration_errors( $errors ) {
    	if ( empty( $_POST['first_name'] ) )
    		$errors->add( 'empty_first_name', '<strong>ERROR</strong>: Please enter your first name.' );
    	if ( empty( $_POST['last_name'] ) )
    		$errors->add( 'empty_last_name', '<strong>ERROR</strong>: Please enter your last name.' );
    	return $errors;
    add_filter( 'registration_errors', 'tml_registration_errors' );
    function tml_user_register( $user_id ) {
    	if ( !empty( $_POST['first_name'] ) )
    		update_user_meta( $user_id, 'first_name', $_POST['first_name'] );
    	if ( !empty( $_POST['last_name'] ) )
    		update_user_meta( $user_id, 'last_name', $_POST['last_name'] );
    add_action( 'user_register', 'tml_user_register' );

    The new fiels appear correctly in the register form but they are not used (they don't appear in the profile page, and the alert are not working even if these fields are required.

    Do you know how I could solve this ?

    Thanks in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic