Help with Adding Error Message on Form
-
I’m working with the profile information form, and I’m trying to add a link to the error message. I tried pretty hard and havn’t been able to do it, and I havn’t found anything online relating to this.
I’m trying to make the add_error function output an error message with a link like this.
UM()->form()->add_error( $key, __( “Toll-Free # Not Added, Click Here to add to your profile.”, ‘ultimate-member’ ) );
Any Ideas?
-
If you want to change an error text use this filter hook
/** * UM hook * * @type filter * @title um_submit_form_error * @description Change error text on submit form * @input_vars * [{"var":"$error","type":"string","desc":"Error String"}, * {"var":"$key","type":"string","desc":"Error Key"}] * @change_log * ["Since: 2.0"] * @usage * <?php add_filter( 'um_submit_form_error', 'function_name', 10, 2 ); ?> * @example * <?php * add_filter( 'um_submit_form_error', 'my_submit_form_error', 10, 2 ); * function my_submit_form_error( $error, $key ) { * // your code here * return $error; * } * ?> */I can’t get it working, here’s what i’ve got.
function um_custom_validate_website( $error, $key) { //$val = $args[$key]; $keys = array('page_url'); $key_product = array('page_url' => 37081, 'headline' => 37080); if(is_active_subscription($key_product[$key])){//37082 = toll-free-number } else{ $link = get_site_url(). '/product/toll-free-phone-number'; /*if(!strpos($val, "http://") && !strpos($val, 'https://')){ UM()->form()->add_error( $key, __( "Please add: https:// or http://", 'ultimate-member' ) ); }*/ my_submit_form_error('Add-On Not Enabled, <a href="'. $link .'">CLICK HERE</a> to to get the Add-On.', $key); //UM()->form()->add_error( $key, __( "Add-On Not Enabled, Go to your Profile Add-Ons on your Profile Menu to add. Top-Right of the Page", 'ultimate-member' ) ); } } add_action( 'um_custom_field_validation_validate_website', 'um_custom_validate_website', 30, 3 ); add_filter( 'um_submit_form_error', 'um_custom_validate_website', 10, 2 ); function my_submit_form_error( $error, $key ) { return $error; }You can try this code snippet:
function um_custom_validate_website( $key, $array, $args ) { $key_product = array( 'page_url' => 37081, 'headline' => 37080 ); //37082 = toll-free-number if ( isset( $args[$key] ) && !is_active_subscription( $key_product[$args[$key]] ) ) { $link = get_site_url() . '/product/toll-free-phone-number'; $error = 'Add-On Not Enabled, <a href="'. $link .'">CLICK HERE</a> to get the Add-On.'; UM()->form()->add_error( $key, $error ); } } add_action( 'um_custom_field_validation_validate_website', 'um_custom_validate_website', 30, 3 );Look at the second code example:
https://docs.ultimatemember.com/article/94-apply-custom-validation-to-a-field
I’m still getting the same result. Any other ideas?
RESULT
Add-On Not Enabled, CLICK HERE to get the Add-On. helloAnd if it helps I’m going through the functions.php of the themes folder.
Active theme’s functions.php file.
Active Child-theme is best because of updating of the main theme may replace current functions.php file.
Use the “Child Theme Configurator” plugin for this:
https://ww.wp.xz.cn/plugins/child-theme-configurator/
-
This reply was modified 3 years, 5 months ago by
missveronica.
Can you post at imgur.com a screen copy of your setting of the website field.
Where can I find the
is_active_subscriptionfunction definition or source file?function is_active_subscription($product){
$output = false;
if(is_user_logged_in()){
/*
$subscriptions = array(
37084, //sort gallery images
37082, //use toll-free number
37081, //link to website
37080, //sales icons
35624, //builder membership um_paid-member
35623, //growth membership um_premium-member
35622, //starter membership um_member
37079 //profile setup
);
*/
//for the growth plan with premium member status$growth_included_subscriptions = array(
37084,37082,37081,37080,37079
);$user = wp_get_current_user();
$user_id = $user->ID;
$profile_builder = false;
$profile_builder_roles = (‘manager, administrator, um_profile-builder’);if(wcs_user_has_subscription($user_id, $product, ‘active’) || user_has_role(‘um_profile-builder’) || user_has_role(‘administrator’) || user_has_role(‘manager’)){
$output = true;
} else if(is_contractor_role(‘um_premium-member’)){
for($i=0; $i<sizeof($growth_included_subscriptions); $i++){
if($growth_included_subscriptions[$i] == $product){
$output = true;
}
}
}}
return $output;
}Here’s the screenshot of the page, we have products that relate to certain fields being activated, so there are going to be 3 different message links total to get the user to the right location.
And here’s a php beautifier so you’re not looking at wordpresses hard to read formatting.
I tried a handful of different ways, but what I was finding was that the default function of error message was overriding what I was doing, even when I used sprintf function for __() function
But I gotta make it easy for the user 🙁
Can you post at imgur.com a screen copy of your setting of the
websitefield in the UM Forms Builder.Post the imgur.com link to the screen copy here in the Forum.
-
This reply was modified 3 years, 5 months ago by
missveronica.
There is something in your add_error function that is overriding my input. I tried to echo the error message and it is outputting properly when echo’d to the top of the page, but it needs to work on your add_error function to get to the right function. add_error is forcing the html to get written as a string of text. Here is a screenshot of my page, and here is the current function that I have, this function should be working, but there is a glitch on the add_error function on your end.
function bp_custom_validate_website( $key, $array, $args ) { $key_product = array( 'page_url' => 37081, 'headline' => 37080 ); //37082 = toll-free-number // if ( isset( $args[$key] ) && !is_active_subscription( $key_product[$args[$key]] ) ) { $url = get_site_url() . '/product/use-toll-free-phone-number'; $error = sprintf( wp_kses( __( 'Add-On Not Enabled <a href="%s">CLICK HERE</a> to get the Add-On.', 'ultimate-member' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) ); //$error = 'Add-On Not Enabled, '. $link .' to get the Add-On.'; UM()->form()->add_error( $key, $error ); //} } add_action( 'um_custom_field_validation_validate_website', 'bp_custom_validate_website', 30, 3 );Did you get a chance to look at this?
-
This reply was modified 3 years, 5 months ago by
The topic ‘Help with Adding Error Message on Form’ is closed to new replies.