Title: Custom Error Message
Last modified: August 22, 2016

---

# Custom Error Message

 *  [wjmisc](https://wordpress.org/support/users/wjmisc/)
 * (@wjmisc)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/custom-error-message-5/)
 * Are there any error message hooks which I could use to display custom error messages
   if for e.g when insert of data to database fail?
 * **Currently using:**
 *     ```
       $result = $wpdb->query($sql);
       if(!$result) {
       $wpcf7->skip_mail = true;
       $error = 'An error has occurred. Please contact the administrator for assistance. <br />Error: '.$wpdb->last_error;
       $omsg = 'return "'. $error .'";';
       add_filter('wpcf7_display_message', create_function('$a', $omsg));
       }
       ```
   
 * that shows the message in green. Any ways to make the message shown on the front
   end red instead?
 * [https://wordpress.org/plugins/contact-form-7/](https://wordpress.org/plugins/contact-form-7/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/custom-error-message-5/#post-5911223)
 * Use the `wpcf7_form_response_output` filter (found in _includes/contact-form.
   php_) to add a class to the response box and in your theme’s stylesheet, add 
   a CSS style rule for the class that makes the message red.
 *  Thread Starter [wjmisc](https://wordpress.org/support/users/wjmisc/)
 * (@wjmisc)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/custom-error-message-5/#post-5911232)
 * Thank you for your response.
    I would like to ask how do I use that filter as
   I am facing some issue trying to use it
 * This is what I have done which does not work. Would appreciate your guidance 
   here.
 *     ```
       $wpcf7->skip_mail = true;
       $content = __('You have already subscribed to our event.',CURRENT_THEME);
       $class = 'wpcf7-validation-errors';
       $output = sprintf( '<div class="%1$s">%2$s</div>', $class,  $content );
       add_filter( 'wpcf7_form_response_output', $output, $class, $content, $wpcf7 );
       ```
   
 *  Thread Starter [wjmisc](https://wordpress.org/support/users/wjmisc/)
 * (@wjmisc)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/custom-error-message-5/#post-5911306)
 * Anyone who knows how to use the filter willing to show some examples on how it
   is done?
 *  [Crish](https://wordpress.org/support/users/carrie_wood/)
 * (@carrie_wood)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-error-message-5/#post-5911477)
 * I have found one plugin which is provide admin settings for different error message
   form different fields.
 * Means if you have field Name then contact form 7 Provide error message “Please
   fill required field” , but by using this plugin you can add “Please enter your
   name”. You can do it without any customization.
 * Have great experience with this plugin , that to author.
    Plugin Link : [https://wordpress.org/plugins/cf7-custom-error-messages/](https://wordpress.org/plugins/cf7-custom-error-messages/)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom Error Message’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

 * [custom error message](https://wordpress.org/support/topic-tag/custom-error-message/)
 * [hook](https://wordpress.org/support/topic-tag/hook/)
 * [message](https://wordpress.org/support/topic-tag/message/)

 * 4 replies
 * 3 participants
 * Last reply from: [Crish](https://wordpress.org/support/users/carrie_wood/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/custom-error-message-5/#post-5911477)
 * Status: not resolved