Hidden Field Validation

By: Brian Penner | Asked: 07/05/2022
ForumsCategory: General questionsHidden Field Validation
Brian Penner asked 2 years ago
Hi, I have a toggle field that I'm using as a confirmation field if another field has an error. I've hidden it with the frm_field_type filter and set up logic to show it with the filter as well. The problem is that the validation fails on that page of the form the first time. If you hit next again it allows you to go to the next page of the form. I've figured out that the error is related to the toggle field being marked as required. I thought hidden fields weren't checked for the required attribute in Formidable. Does anyone know if that's true? 
1 Answers
Victor Font answered 2 years ago
I have a theory that you may be running into a conflict with how Formidable displays multi-page forms. When you hit next and previous in a multi-page form, Formidable converts all fields that are not displayed on the resulting page to hidden fields. You can confirm this by examining the form's source code in your browser's inspection tool. Fields that are supposed to be shown on a specific page are converted from hidden to their original defined type. It's hard to say the exact cause of the issue you are experiencing without further debugging in your system, but it's possible your code is actually working and Formidable is resetting it when the page displays. To test what's happening in your system, I would use a PHP debugger like Kint or Xdebug that allows you to set a break point so that you can pause code execution when the filter is invoked to examine the when and how the field type is changing. If your code is working, you'll see the field's type change. If it changes as you expect, but if the toggle is still a radio button on the form, then Formidable changed it back because of the multi-page functionality. It's unusual that you are using this filter to change a field type. Normally, hiding showing fields is handled through conditional statements or jQuery .hide() and .show().
Brian Penner replied 2 years ago

Well, I tried the jQuery method but was running into problems with an error popping up due to the hidden field being required. https://share.cleanshot.com/ND6g06

Victor Font replied 2 years ago

If you're going to use PHP, there are other hooks you can use to change both the readonly flag and field type at the same time. They are frm_setup_new_fields_vars and frm_setup_edit_fields_vars.

Field type is $values['type'] and readonly is $values['read_only'].

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