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 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)
Viewing 1 replies (of 1 total)
The topic ‘PHP Snippets Not Working’ is closed to new replies.