Custom Validation for Subscription Form
-
Hello,
I am trying to have a custom validation for the mail address field. I would like that only subscribers of a special mail domain are allowed to subscribe.
I have used your code example here:
https://docs.ultimatemember.com/article/94-apply-custom-validation-to-a-fieldand modified it a bit:
add_action(‘um_submit_form_errors_hook_’,’um_custom_validate_mail’, 999, 1);
function um_custom_validate_mail( $args ) {
global $ultimatemember;
if( isset( $args[‘user_email’] ) && filter_var($args[‘user_email’], FILTER_VALIDATE_EMAIL) ){
$explode_array = explode(“@”, $args[‘user_email’]);
$domain = $explode_array[1];if( $domain != “<MAIL_DOMAIN>” ){
$ultimatemember->form->add_error( ‘user_email’, ‘Your mail address must contain the domain <MAIL_DOMAIN>.’ );
}
}
}
Also I have set the parameter to um_custom_validate_mail in the form builder field settings under “custom action”.I have this error in the webserver log:
2019/01/23 14:24:49 [error] 19924#19924: *353577 FastCGI sent in stderr: “PHP message: PHP Fatal error: Uncaught Error: Call to a member function add_error() on null in /var/www/wp-content/themes/my_theme/inc/custom-plugin-actions.php:15
Stack trace:
#0 /var/www/wp-includes/class-wp-hook.php(286): um_custom_validate_mail(Array)
#1 /var/www/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#2 /var/www/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#3 /var/www/wp-content/plugins/ultimate-member/includes/core/um-actions-form.php(236): do_action(‘um_submit_form_…’, Array)
#4 /var/www/wp-includes/class-wp-hook.php(286): um_submit_form_errors_hook(Array)
#5 /var/www/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array)
#6 /var/www/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#7 /var/www” while reading response header from upstream, client: 5.15.5.15, server: domain.tld, request: “POST /register/ HTTP/2.0”, upstream: “fastcgi://unix:/var/lib/php7.0-fpm/web889.sock:”, host: “www.domain.tld”, referrer: “https://www.domain.tld/register/”I’d be happy for some info/help..
Thank you
- The topic ‘Custom Validation for Subscription Form’ is closed to new replies.