Skip Navigation

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

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 7 años, 1 mes. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: ,

Este tema contiene 8 respuestas, tiene 2 mensajes.

Última actualización por Christian Cox hace 5 años, 5 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#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.