Support » Plugin: Theme My Login » Validation of profile form

Viewing 4 replies - 1 through 4 (of 4 total)
  • Just an update on this, this code above works in the admin profile page. So it’s good to know it’s working as it should in native WordPress.

    However, I’m using the theme my login profile page on the front end. Is it possible for this validation code above to apply to the front end form? This would be perfect!


    Plugin Author Jeff Farthing


    By default, the code for profile updating does not run unless on the actual Login page, effectively rendering default_action='profile' useless.

    TML 6.3 (coming soon) will have better handling of such scenarios.

    Thanks very much for replying. Is there a work around in the mean time?

    My profile page works and in fact the user_profile_update_errors hook actually does seem to validate the fields and stop the form saving if validation fails. But for the life of me I can’t seem to get the errors to appear.

    I’ll send over a thank you, whatever your fee is. I don’t want to get support for free and I’m more than happy to pay you for your support.

    This is very important so if there is a work around until the 6.3 release and it’s worth your time to help me for your fee, please let me know.

    Many thanks,

    I actually managed to find a solution to this, so I thought I would share it.

    It doesn’t require making any changes to the hard code of the plugin, which is good. You simply just need to add this code in the profile-form.php template file that you place in your theme.

    Place it just above this line:

    template->the_action_template_message( 'profile' );


    global $theme_my_login;
    $current_user = wp_get_current_user();

    $errors = edit_user( $current_user->ID );

    if ( !is_wp_error( $errors ) ) {
    $redirect = add_query_arg( array( ‘updated’ => ‘true’ ) );
    wp_redirect( $redirect );

    $theme_my_login->errors = $errors;

    if ( is_wp_error( $errors ) ) {
    $error_string = $errors->get_error_messages();
    echo ‘<p class=”error”>’;
    foreach ($error_string as $error_message) {
    echo $error_message . ”; }
    echo ‘</p>’;

    Used in conjunction with the user_profile_update_errors filter to add custom validation the code above validates the profile form fields perfectly.

    The only problem I’ve found is that once all validation has been passed and all fields are complete and saved correctly, it then ironically displays all error messages and the whole form fails validation (even though the form is complete and correct. I think this is because I’m using ‘$errors = edit_user( $current_user->ID );’ above.

    The edit_user() function for some reason not only updates a user but tries to create a new user too if there is no current user to update. So I think that when all the validation passes it then tries to create a new user and expects all the fields to be passed through again. This is what’s causing the new validation errors.

    This is where the add_query_arg comes in above, which appends an “update” parameter to the url when validation is first successful. I then include the code below so users are sent to an appropriate page as soon as they successfully complete the profile so they don’t see the new validation failures:

    <?php if ( isset($_GET['updated']) ) : wp_redirect( get_permalink( get_page_by_title('page')) ); ?>

    This isn’t ideal but works well for my needs. I think this problem is because I’m using the user_edit() function. It would be great to get some feedback on this method and if there are any improvements I could make.

    Many thanks,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Validation of profile form’ is closed to new replies.