• Resolved eadwig

    (@eadwig)


    Hello

    Thanks for the useful plugin. It’s served as many purposes as I needed for a website except for one function as shown in the title of this post.

    I read the page below and understood the registration_errors filter is required to this end:

    https://docs.thememylogin.com/article/62-adding-extra-registration-fields

    However, the filter is a complex one and I am wondering if there is an alternative solution that can make added custom fields required.

    Provision of a workaround or two would be appreciated.

    Looking forward to hearing from you,

    Ead

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jeff Farthing

    (@jfarthing84)

    The documentation you linked to shows you exactly how to do it. What troubles are you having?

    Thread Starter eadwig

    (@eadwig)

    Hello

    I embedded the PHP code given for each Example ( https://docs.thememylogin.com/article/62-adding-extra-registration-fields.) in functions.php and theme-my-login-custom.php

    Then I received the error message as below:

    Fatal error: Cannot redeclare validate_tml_registration_form_fields()

    For clarification, the code added in theme-my-login-custom.php is:

    function add_tml_registration_form_fields() {
            tml_add_form_field( 'register', 'notices', array(
     		'type'     => 'checkbox',
    		'label'    => '当サイトからのお知らせメールを受け取る。',
    		'value'    => tml_get_request_value( 'notices', 'post' ),
    		'id'       => 'notices',
    		'priority' => 15,
    	) );
    }

    And the code added in functions.php is:

    
    function validate_tml_registration_form_fields( $errors ) {
    		if ( empty( $_POST['notices'] ) ) {
    			$errors->add( 'empty_notices', '<strong>ERROR</strong>' );
    		}
    		return $errors;
    	}
    	add_filter( 'registration_errors', 'validate_tml_registration_form_fields' );
    	function save_tml_registration_form_fields( $user_id ) {
    		if ( empty( $_POST['notices'] ) ) {
    			$errors->add( 'empty_notices', '<strong>ERROR</strong>' );
    		}
    	}
    	add_action( 'user_register', 'save_tml_registration_form_fields' );
    

    For now, I just want to validate the one checkbox type field.
    Please advise me what to correct.

    • This reply was modified 5 years, 7 months ago by eadwig.
    Plugin Author Jeff Farthing

    (@jfarthing84)

    Remove the code from functions.php and place all of it in theme-my-login-custom.php.

    Thread Starter eadwig

    (@eadwig)

    Putting all the code as shown above into theme-my-login-custom.php still returns the following error:

    Fatal error: Cannot redeclare validate_tml_registration_form_fields() (previously declared in /virtual/minnov/public_html/[domain name]/wp-content/plugins/theme-my-login-custom.php:33) in /virtual/minnov/public_html/[domain name]/wp-content/plugins/theme-my-login-custom.php on line 55

    What does ‘Cannot redeclare validate_tml_registration_form_fields() ‘ indicate?

    Plugin Author Jeff Farthing

    (@jfarthing84)

    It means you’ve use the same name to define two different functions, both on line 33 and 55. Function names must be unique.

    Thread Starter eadwig

    (@eadwig)

    Apologies, I was too confused not to notice the function duplicates.

    The code given in your Advanced Topics indeed works to validate the form controls!

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Making added custom fields required’ is closed to new replies.