• Resolved substa

    (@substa)


    Hello,

    in a previous work I successfully added a checkbox to the registration form as described in the documentation:
    https://www.jfarthing.com/development/theme-my-login/adding-extra-registration-fields/

    So, I used this code:
    register-form.php

    <textarea id="disclaimer<?php $template->the_instance(); ?>"><?php include('disclaimer.txt'); ?></textarea><br />
            <input type="checkbox" name="acceptdisclaimer" id="acceptdisclaimer<?php $template->the_instance(); ?>" /> ACCEPT

    theme-my-login-custom.php

    function tml_register_errors( $errors ) {
        if ( !$_POST['acceptdisclaimer'] )
            $errors->add( 'no_disclaimer', '<strong>ERROR</strong>: NO DISCLAIMER' );
        return $errors;
    }
    add_filter( 'registration_errors', 'tml_register_errors' );

    And it works fine!

    Now, I need to implement this on a wordpress network!
    The previous code doesn’t work.
    So, I’m trying this code:

    ms-signup-user-form.php

    <textarea id="disclaimer<?php $template->the_instance(); ?>"><?php include('disclaimer.txt'); ?></textarea><br />
            <input type="checkbox" name="acceptdisclaimer" id="acceptdisclaimer<?php $template->the_instance(); ?>" /> ACCEPT

    theme-my-login-custom.php

    function tml_validate_user_signup ( $result ) {
        if ( !$_POST['acceptdisclaimer'] ) {
    			$result['errors']->add('no_disclaimer', "NO DISCLAIMER");
        }
    
    return $result;
    }
    add_filter('wpmu_validate_user_signup', 'tml_validate_user_signup', 10, 3);

    It doesn’t seem to work either… (Checkbox added, but no error if it is not checked)

    Any help?

    https://www.ads-software.com/extend/plugins/theme-my-login/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter substa

    (@substa)

    No solution to suggest?

    Plugin Author Jeff Farthing

    (@jfarthing84)

    That should work. Try removing the priority and the argument count (there isn’t 3 arguments, just 1).

    Thread Starter substa

    (@substa)

    No, it doesn’t work.
    But I noticed a strange thing:
    If I try to add an user in the site admin dashboard, it returns the “NO DISCLAIMER” error, so it seems “tml_validate_user_signup” works for the admin dashboard, and not for the thememylogin registration form…

    I need the exact opposite behaviour (No error for administrators, and validate forms for normal users)

    Plugin Author Jeff Farthing

    (@jfarthing84)

    Add an is_admin clause to the beginning of the function to disable it there:

    if ( is_admin() )
        return;
    Thread Starter substa

    (@substa)

    Ok, the is_admin clause is perfect, thanks.

    However, still no error on user registration form.
    After several tests, now I’m able to interrupt the registration if checkbox is not checked, but no errors are displayed.

    This is the code in theme-my-login-custom.php:

    function tml_validate_user_signup ( $result ) {
        if ( is_admin() )
            return;
    
        if (!($_POST['acceptdisclaimer']) ) {
    			$result['errors']->add('no_disclaimer', 'NO DISCLAIMER');
        }
    
    return $result;
    }
    add_filter('wpmu_validate_user_signup', 'tml_validate_user_signup');
    Plugin Author Jeff Farthing

    (@jfarthing84)

    Errors are handled differently on multisite. If you look at the ms-signup-user-form.php, you’ll see how each field has it’s own error handler. Copy that idead for your custom field.

    <?php if ( $errmsg = $errors->get_error_message( 'no_disclaimer' ) ) { ?>
    	<p class="error"><?php echo $errmsg; ?></p>
    <?php } ?>
    Thread Starter substa

    (@substa)

    Ok, perfect, it works! Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding Extra Registration Fields and Validate the new fields on NETWORK’ is closed to new replies.