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.