Limit frm_validate_field_entry to specific forms

By: Hans Baumhardt | Asked: 04/26/2023
ForumsCategory: Code HelpLimit frm_validate_field_entry to specific forms
Hans BaumhardtHans Baumhardt asked 2 years ago

I would like to limit custom field validation code in a shared library (say functions.php) to only work on specific forms.

 

Using logic on the [ if($posted_field->id == n)  ] value means I have to manually ensure that forms which the validation does not apply to do not contain those field values. With a number of validations * fields * forms its becoming a significant PITA to manage.

 

Is there any way to get ones hands on the form.id during the frm_validate_field_entry event ?

 

Be great to have access to similar logic we have in postprocessing like frm_after_create_entry with [ if ( $args['form']->id == 2 ) ]

 

ps frm_validate_field_entry $args['id'] is field.id , not form.id

2 Answers
Victor Font answered 2 years ago
It's in the PHP $_POST associative array. It should be $_POST['form_id']. If for some reason that doesn't work for you, use the Kint debugger to examine the $_POST content.
Hans BaumhardtHans Baumhardt answered 2 years ago

Many thanks, works perfectly! Wasn't aware that $_POST was available during frm_validate_field_entry, assumed formidable was preprocessing before the PHP global triggers.  

$valid_form_ids = array(2,5);
if (! in_array($_POST['form_id'], $valid_form_ids)) {return;}

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right