Skip Navigation

[Resolved] cred_form_validate is called TWICE, is that normal?

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a cred_form_validate hook applied to a CRED form. With JavaScript disabled, I can see that the hook is fired twice by monitoring server logs. With JavaScript enabled, the hook is fired once as expected.

Solution: This problem has been resolved in the latest release of Forms 2.4

Relevant Documentation: https://toolset.com/errata/cred_form_validate-api-hook-called-twice-when-javascript-is-disabled/

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by Christian Cox 4 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#580854

Dear Support,

I have a Generic Field (a checkbox) added to a form, just like this "Terms of use checkbox field" in this tutorial:
https://toolset.com/documentation/user-guides/cred-training-course/part-3-adding-generic-fields-conditional-groups-form/

The tutorial reads: "The Terms of use field is always required and the ad will not be submitted until a user checks it."

It is only true if the browser's JavaScript is ON. Without JavaScript, the form can be posted even with the checkbox unchecked. You should point this out in the tutorial and provide an example hook to resolve it.

While I was trying to solve it with a "cred_form_validate" hook (see below), I noticed that my hook is called TWICE while the form is being executed. Is that a normal behavior?

add_action('cred_form_validate_1111', 'site_cred_form_validate_1111', 10, 2);
function site_cred_form_validate_1111($error_fields, $form_data) {
	list($fields, $errors) = $error_fields;
	error_log(print_r($fields, true)); // -> THIS ONE SHOWS UP IN THE LOG TWICE, HENCE THE HOOK IS CALLED TWICE
	if (empty($fields['terms-accepted']['value'])) {
		$errors['terms-accepted'] = 'This field is required!';
	}
	return array($fields,$errors);
}
#580855

Please note that I edited the code part of my first post as I mistakenly posted a previous, non-working version of it.

#580917

While I was trying to solve it with a "cred_form_validate" hook (see below), I noticed that my hook is called TWICE while the form is being executed. Is that a normal behavior?
It's not normal when JavaScript is active, but I'm not clear about what should be expected without JavaScript. Let me reach out to my 2nd tier support team to see what the expected behavior is when JS is disabled. Please stand by and I will update you when I have some information to share.

#581297

Just a quick update to let you know that I'm still waiting to receive some feedback on this question, so I don't have anything substantial to report just yet.

#582384

Hi, after some discussion in the team, we have determined that we may be able to optimize the validation code flow to prevent the validation hook from being called multiple times if JavaScript is disabled. The developers have agreed to create a ticket to address this in a future release of CRED. I'll keep you updated here as work progresses, though I do not have a timeline available for you yet.

#582417

Hi,
Thanks for the report. Since the issue doesn't seem to have a side effect, I can live with it.
Regards,
G

#582534

Alright, let's close out this ticket and I will be able to reply to you here as work progresses. Thanks!

#588094

For future reference - an erratum has been published regarding this issue and our developers are investigating a permanent solution:
https://toolset.com/errata/cred_form_validate-api-hook-called-twice-when-javascript-is-disabled/

#1277869

For all interested parties, the permanent solution for this issue has been released in Forms 2.4.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.