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 6 years, 10 months ago by
eadwig.
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?
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.