• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Prevent hidden required fields being validated.

Prevent hidden required fields being validated. 13 years 8 months ago #11491

Hi,

I have a form with several fieldsets, each containing several input fields, most of which are required. Some of those fieldsets are hidden and become visible after clicking a radio button. So far so good. The problem arises when submitting the form and required fields get validated while they are hidden.

I found this thread with a sort of work around, but it has some major drawbacks:
  • The proposed solution implements front end validation, whereas default required field validation is done in the back end. Front end validation is cool, but only acceptable in combination with back end validation from the perspective of graceful degradation.
  • The solution only takes one field into account, using several lines of code to handle just one input field and referencing hard coded component id's. Having multiple fieldsets, each containing multiple fields, makes this approach a maintenance nightmare.

Is there a more elegant and robust solution to handle multiple required fields at once, also allowing for back end validation?
The administrator has disabled public write access.

Re:Prevent hidden required fields being validated. 13 years 7 months ago #11496

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

Another workaround for this would be to modify the method through which RSForm! Pro applies the validation rules...however this would require heavy source code modifications to the component. We do not recommend this as the modifications will be overwritten upon updating RSForm! Pro.

It would be best to consider implementing the validation method that I posted on our forum.
The administrator has disabled public write access.

Re:Prevent hidden required fields being validated. 13 years 7 months ago #11514

Hi Bogdan,

Thanks for the reply.

I understand that you do not recommend modifcations to the source code and I definitely prefer not to do that. However, the validation method you posted in the forum, has too many drawbacks.

I took a closer look at the code that applies the validation and in fact the required modifications are not that heavy at all. The trick is to add a custom validation as described in section Customizing RSForm! Pro - Custom validation rules of the documentation. There is one problem though: by default empty fields don't get validated. This can easily be solved by changing line 1367 in methode validateForm() of class RSFormProHelper (in .../administrator/components/com_rsform/helpers/rsform.php). If you remove the part "&& strlen(trim($post[$data])) > 0" from the if statement, empty fields are validated just like any other field. So
if (isset($post['form'][$data['NAME']]) && !is_array($post['form'][$data['NAME']]) && strlen(trim($post['form'][$data['NAME']])) > 0 && is_callable(array('RSFormProValidations', $validationRule)) && call_user_func(array('RSFormProValidations', $validationRule),$post['form'][$data['NAME']],isset($data['VALIDATIONEXTRA']) ? $data['VALIDATIONEXTRA'] : '' ) == false)
becomes
if (isset($post['form'][$data['NAME']]) && !is_array($post['form'][$data['NAME']]) && is_callable(array('RSFormProValidations', $validationRule)) && call_user_func(array('RSFormProValidations', $validationRule),$post['form'][$data['NAME']],isset($data['VALIDATIONEXTRA']) ? $data['VALIDATIONEXTRA'] : '' ) == false)
I'm not sure why empty fields currently are not validated, but if there is a good reason, please let me know. If there is no good reason, you may consider implementing the above modifcation in a future version, thereby allowing more flexibility for custom validations.

One additional question: do (custom) validations also get overwritten when updating RSForm! Pro? If so, I suggest you make that clear in the documentation. It would be even better if you implement a solution to prevent overwriting custom validations. The ability to create validations is quite powerful, but only if they don't get overwritten.

Kind regards.
The administrator has disabled public write access.

Re:Prevent hidden required fields being validated. 13 years 7 months ago #11515

It seems I have been a little too hasty. My solution only works for fields that that support validation rules, such as regular text fields and text area's but not radio buttons, checkboxes, select lists, etc. That's a bummer :(
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!