Validate submit event field Snippets

Validate submit event field Snippets

Validation refers to the process of checking the accuracy of the information provided. When an event is posted on a website, it determines the credibility of the organizer. Hence it becomes of utmost importance to provide the details accurately.

The following steps must be taken to check validation on a particular field while submitting an event form:

  1. Open your child theme’s function.php file.
  2. Add the following code:
  1. add_filter('submit_event_form_validate_fields', 'wpem_submit_event_form_validate_fields', 10, 3);
  2.    function wpem_submit_event_form_validate_fields($string, $fields, $values)
  3.     {
  4.         foreach ( $fields as $group_key => $group_fields )
  5.         {
  6.             foreach ( $group_fields as $key => $field )
  7.             {           
  8.                 if($key == 'phone_no')
  9.                 {
  10.                     if(strlen($values[$group_key][$key]) <= 10)
  11.                     {
  12.                         return new WP_Error( 'validation-error', __( 'Please Enter 10 Digit Number', 'wp-event-manager' ) );
  13.                     }
  14.                 }
  15.             }
  16.         }
  17.         return $string;
  18.     }
Save changes.



    • Related Articles

    • Event Fields

      Event Submission Form Custom Fields Settings The field editor sub-menu under Event Listings (WP Admin>> Event Manager >> Field Editor) offers flexibility to edit field labels including Type of data, description, placeholder and more. The settings ...
    • Event Tag snippets

      The Event Tags in WP Event Manager are designed to simplify the process of searching events. It allows users to search for events quickly with targeted keywords. Event Tags can be customized with the help of below mentioned Event Tag snippet. Here ...
    • How To Install WP Event Manager Add ons

      WP Event Manager offers a huge number of addons that help you strengthen your WordPress site with some amazing and very useful event management features and functionalities. While installing a premium addon, you need to ensure that you already have ...
    • How to display additional custom fields on a single event page?

      This WP Event Manager tutorial shows you how you can add the custom event fields to a single event page. It requires customizing your PHP file. Display additional custom fields on a single event page To display additional custom fields on a single ...
    • Event Tags

      Using the Event Tags plugin, you can add a new ‘event tags’ field to the submit process, show events filtered by tag via a shortcode, and add tag filtering to the standard events shortcode. Installing The Plugin The installation process is the same ...