fbpx

How can we help?

Validate submit event field Snippets

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

The following steps can be implemented in order to add extra validation on a particular field while submitting an event form:

  1. Open your child theme’s function.php file.
  2. Add code:
  3. <?php
    
    add_filter('submit_event_form_validate_fields', 'wpem_submit_event_form_validate_fields', 10, 3);
       function wpem_submit_event_form_validate_fields($string, $fields, $values)
        {
            foreach ( $fields as $group_key => $group_fields )
            {
                foreach ( $group_fields as $key => $field ) 
                {            
                    if($key == 'phone_no')
                    {
                        if(strlen($values[$group_key][$key]) <= 10)
                        {
                            return new WP_Error( 'validation-error', __( 'Please Enter 10 Digit Number', 'wp-event-manager' ) );
                        }
                    }
                }
            }
            return $string;
        }
    
    ?> 
    
  4. Save changes
Was this article helpful?
How can we improve this article?