Title: PHP Snippets Not Working
Last modified: February 8, 2022

---

# PHP Snippets Not Working

 *  [raven127](https://wordpress.org/support/users/raven127/)
 * (@raven127)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/php-snippets-not-working/)
 * Hi I’m trying to add a code snippet to do some custom validatoin on my form (
   made with WPForm extension). Some snippets I’ve added with the Snippets plugin
   don’t seem to work, for example [here](https://wpforms.com/developers/how-to-provide-an-age-restriction-on-the-datepicker-form-field/)
   there are two example snippets, one using javascript which works fine:
 *     ```
       function wpf_dev_check_age() {
       ?>
       <script>
           jQuery(function($) {
   
               window.wpforms_1425_10 = window.wpforms_1425_10 || {};
               window.wpforms_1425_10.datepicker = {
                   mode: "single",
                   onClose: function(selectedDates, dateStr, instance) {
   
                       var year = selectedDates[0].getFullYear();
                       if (year < 2007 || year > 2015) {
                           alert( 'Minimum age requirement is 5 or maximum age requirement is 12' );
                           this.clear();
                       }
   
                   }
   
               }
           });
       </script>
       <?php
       }
       add_action( 'wpforms_wp_footer', 'wpf_dev_check_age', 10 );
       ```
   
 * and another written with PHP which does not work:
 *     ```
       function wpf_dev_process( $fields, $entry, $form_data ) {
   
           // Optional, you can limit to specific forms. Below, we restrict output to
           // form #1425.
           if ( absint( $form_data['id'] ) !== 1425 ) {
               return $fields;
           }
   
           if (isset($fields[10]['value'])) {
               $timestamp = strtotime($fields[10]['value']);
               $year=date('Y',$timestamp);
           }
   
           if($year < 2007 || $year> 2015) {
   
               // Check the field ID 10 and show error message at the top of form and under the specific field
               wpforms()->process->errors[ $form_data['id'] ] [ '10' ] = esc_html__( 'Minimum age requirement is 5 or maximum age requirement is 12', 'plugin-domain' );
           }
       }
       add_action( 'wpforms_process', 'wpf_dev_process', 10, 3 );
       ```
   
 * I need to write one similar to the PHP one which does not work, does anyone know
   why its not working? Any help would be super appreciated.
 * Cheers

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-snippets-not-working/#post-15621471)
 * Unfortunately, I’m not at all familiar with the forms plugin you’re using, and
   so I’m not sure how to go about resolving this.
 * I recommend asking this in a forum specific to that plugin, where there should
   be people with more relevant knowledge.

Viewing 1 replies (of 1 total)

The topic ‘PHP Snippets Not Working’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/php-snippets-not-working/#post-15621471)
 * Status: not a support question