WordPress.org

Ready to get started?Download WordPress

Forums

Theme My Login
[resolved] Additional fields in register-form.php (8 posts)

  1. Sebastian
    Member
    Posted 3 years ago #

    Hello,

    I'd like to add some text-fields in the registration form:

    firstname
    lastname
    website

    ...so the 'official' fields from wordpress. In my case it should be set obgligatory during the registration process.

    Thx!
    Sebastian

    http://wordpress.org/extend/plugins/theme-my-login/

  2. Jeff Farthing
    Member
    Plugin Author

    Posted 3 years ago #

    Copy register-form.php into your current theme's directory and edit it as you see fit.

    Please note that simply adding the fields will not save the data. You will need to use provided hooks to achieve your desired results.

    You will want to use registration_errors to require fields and tml_new_user_registered to save the data.

  3. Sebastian
    Member
    Posted 3 years ago #

    You will need to use provided hooks to achieve your desired results.

    Could you specify it? I'm not quite familiar in this stuff :/ So if I would add a new input for the available 'user_company' like

    <input style="width:300px;height:34px;line-height:27px;border:1px solid #ececec;outline:none;padding-left:5px;color:#585858;float:left; background:url(/images/search_bg.png);" type="text" name="user_company" id="user_company<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'user_company' ); ?>" size="20" />

    ...it would safe the infos?

  4. Jeff Farthing
    Member
    Plugin Author

    Posted 3 years ago #

    Create /wp-content/plugins/theme-my-login-custom.php and add this code to it.

    After that, you will be able to access the property via the WP_User object: $user->user_company.

  5. Sebastian
    Member
    Posted 3 years ago #

    This sounds really really great, thank you for this! And If I'd like to offer the fields user_company and e.g. user_telephone... BUT only make the user_company obligatory, I only need to add the user_company to the registration_errors-function?

  6. KyleEmmm
    Member
    Posted 3 years ago #

    I don't believe so...I'm following this as I'm looking to make some changes to the register-form.php file as well.

    Don't quote me on this, but I think Jeff is saying that you will have to enter new registration_errors and new tml_new_user_registered variables to the theme-my-login-custom.php file for each additional item you wish to add to your register-form.php file. Jeff's example only shows how to add a line for Companies (user_company, empty_company).

  7. Sebastian
    Member
    Posted 3 years ago #

    Hello Kyle, thx for your reply! This sounds complicated, a bit too complicated, so I guess I should avoid adding additional and obligatory registration-fields. Hopefully, Jeff will include this option (custom-fields) as an future feature one day. Thx for you work and fast support! Sebastian

  8. Saabana
    Member
    Posted 3 years ago #

    hello
    I add some extra fields ` <p>
    <label for="first_name"><?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( 'user_first_name' ); ?>" size="20" maxlength="255" alt="First Name" />
    </p>
    <p><label for="last_name"><?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( 'user_last_name' ); ?>" size="20" maxlength="255" alt="Last Name" />
    </p>
    <p>
    <label for="user_phone<?php $template->the_instance(); ?>"><?php _e( 'Phone', 'theme-my-login' ) ?></label>
    <input type="text" name="user_phone" id="user_phone<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'user_phone' ); ?>" size="20" />
    </p>

    and also I Create /wp-content/plugins/theme-my-login-custom.php and add some code to it.
    <?php

    function registration_errors( $errors ) {
    if ( empty( $_POST['user_phone'] ) )
    $errors->add( 'empty_phone', '<strong>ERROR</strong>: Please enter your phone number.' );
    return $errors;
    }
    add_action( 'registration_errors', 'registration_errors' );

    function tml_new_user_registered( $user_id ) {
    update_user_meta( $user_id, 'user_phone', $_POST['user_phone'] );
    }
    add_action( 'tml_new_user_registered', 'tml_new_user_registered' );

    ?>`
    and still didn't get the field working for store data in profile form and error when left my phone empty
    and thanks for this plugin

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic