Title: Help with Adding Error Message on Form
Last modified: December 9, 2022

---

# Help with Adding Error Message on Form

 *  Resolved [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/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](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/website?output_format=md)
   to add to your profile.”, ‘ultimate-member’ ) );
 * Any Ideas?

Viewing 15 replies - 1 through 15 (of 33 total)

1 [2](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/page/2/?output_format=md)

 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16275330)
 * [@baddon250](https://wordpress.org/support/users/baddon250/)
 * 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;
        * }
        * ?>
        */
       ```
   
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16275476)
 * 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;
         }
       ```
   
 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276419)
 * [@baddon250](https://wordpress.org/support/users/baddon250/)
 * 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](https://docs.ultimatemember.com/article/94-apply-custom-validation-to-a-field)
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276471)
 * I’m still getting the same result. Any other ideas?
 * RESULT
    Add-On Not Enabled, [CLICK HERE](https://biltpros.com/product/toll-free-phone-number)
   to get the Add-On. hello
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276474)
 * And if it helps I’m going through the functions.php of the themes folder.
 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276500)
 * [@baddon250](https://wordpress.org/support/users/baddon250/)
 * 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://wordpress.org/plugins/child-theme-configurator/](https://wordpress.org/plugins/child-theme-configurator/)
    -  This reply was modified 3 years, 5 months ago by [missveronica](https://wordpress.org/support/users/missveronicatv/).
 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276504)
 * [@baddon250](https://wordpress.org/support/users/baddon250/)
 * Can you post at [imgur.com](https://imgur.com/) a screen copy of your setting
   of the website field.
 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276521)
 * [@baddon250](https://wordpress.org/support/users/baddon250/)
 * Where can I find the `is_active_subscription` function definition or source file?
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276525)
 * 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; }
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276526)
 * 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.
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276527)
 * And here’s a php beautifier so you’re not looking at wordpresses hard to read
   formatting.
 * [https://beautifytools.com/php-beautifier.php](https://beautifytools.com/php-beautifier.php)
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276528)
 * 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 🙁
 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16276540)
 * [@baddon250](https://wordpress.org/support/users/baddon250/)
 * Can you post at [imgur.com](https://imgur.com/) a screen copy of your setting
   of the `website` field in the UM Forms Builder.
 * Post the [imgur.com](https://imgur.com/) link to the screen copy here in the 
   Forum.
    -  This reply was modified 3 years, 5 months ago by [missveronica](https://wordpress.org/support/users/missveronicatv/).
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16290901)
 * 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.
 * > [View post on imgur.com](https://imgur.com/a/7QHbrgV)
 *     ```
       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 );
       ```
   
 *  Thread Starter [baddon250](https://wordpress.org/support/users/baddon250/)
 * (@baddon250)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/#post-16321544)
 * Did you get a chance to look at this?

Viewing 15 replies - 1 through 15 (of 33 total)

1 [2](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/page/2/?output_format=md)

The topic ‘Help with Adding Error Message on Form’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

 * 33 replies
 * 4 participants
 * Last reply from: [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * Last activity: [2 years, 11 months ago](https://wordpress.org/support/topic/help-with-adding-error-message-on-form/page/3/#post-16841577)
 * Status: resolved