frm_validate_field_entry isn't validating

Labels

This Discussion is public

Notifications

Hi everyone,

I think my issue is pretty basic, but I haven't been able nail down a solid solution yet.

I have a form on a page with a single text field where the user can enter a Promo code (there's only 1 code). If the promo code entered isn't the right one, then I want the form to output an error. I only have Formidable Lite so conditional logic isn't available which has led me to my current situation below. I used the example code from here: https://formidableforms.com/knowledgebase/frm_validate_field_entry/

I have tried switching the priority from 10 to 5, but no dice. I have also confirmed that 54 is the correct field ID.

Has anyone else had a similar situation?

add_filter('frm_validate_field_entry', 'my_custom_validation', 10, 3);
function my_custom_validation($errors, $posted_field, $posted_value){
if ($posted_field->id == 54) {
if(!in_array($posted_value, array('backup','BACKUP'))) {
//if it doesn't match up, add an error:
$errors['field'. $posted_field->id] = 'That field is wrong!';
}
}
return $errors;
}

On the surface, your code looks correct. This will require deeper troubleshooting to examine the values being passed to the function as well as testing if the function if firing at all.

If you are familiar with using PHP's var_dump(), print_r() and debug_backtrace(), then I would use these functions to examine the actual values. If not, I suggest a Kint plugin that replaces PHP's tools. https://wordpress.org/plugins/kint-php-debugger/.

To use Kint in your function, I would activate the plugin and add the Kint calls to your function:

function my_custom_validation($errors, $posted_field, $posted_value){
if ($posted_field->id == 54) {
d($errors);
d($posted_field);
d($posted_value);
if(!in_array($posted_value, array('backup','BACKUP'))) {
//if it doesn't match up, add an error:
$errors['field'. $posted_field->id] = 'That field is wrong!';
}
}
return $errors;
}

Reply to this Discussion