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

    • Remove existing field from event submission form

      Removing fields from event the event submission form In this guide, you will learn about how you can remove existing fields from the event submission form and how you can remove some social fields from the organizer section. Remove existing field ...
    • Installation of WP Event Manager

      Automatic Installation of FREE WP Event Manager Installing WP Event Manager is just a matter of a few clicks. You can add WP Event Manager to your website by using the dashboard offered to you at the backend of the CMS. To install the plugin ...
    • Create or pick categories from Free/ Core WP Event manager

      Events are classified into various types based on the kind of visitors they have. Visitors come from different backgrounds. That is why an event organizer or admin must ensure that they make a lot of event categories available to their clients. This ...
    • Adding a country field for events

      In this guide, you will learn about how you can add a country field to your event submission form based on the Event Submission Form Fields doc and showcase it on a single event listing. Adding a field to the frontend In order to add fields on the ...
    • Updating WP Event Manager

      Automatic Update WP Event Manager always strives to achieve perfection in every way and that is why we constantly update our plugins so that you can enjoy their innovative features. Here are the steps that you need to take to update WP Event Manager: ...