Skip Navigation

[Résolu] I need Validation for a Checkbox field

This support ticket is created Il y a 6 années et 6 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Nigel Il y a 6 années et 6 mois.

Assisté par: Nigel.

Auteur
Publications
#907196

I need to do exactly what this guy did: https://toolset.com/forums/topic/cant-validate-checkboxes/ except that I am not using CRED form.

Is it possible to force validation of a checkbox field in my Post Fields area or via a code snippet like the one in the linked thread?

Thanks,

Marcus

#907317

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Marcus

You need this for a checkboxes field (plural), right? Where at least one of the checkboxes must be checked.

That's not too difficult to do with CRED forms, as described in the other thread, as you can use the validation hook of the CRED API.

There is no equivalent hook to do the same in core WordPress (but it might be added: https://core.trac.wordpress.org/ticket/43019).

The only alternative I can think of is to write a bespoke JavaScript solution to disable submitting the form until one of the checkboxes has been checked.

For information about the best way to enqueue JS on the admin post edit screen for custom post types, see this: https://wordpress.stackexchange.com/a/243738/35739

The JS you write itself will want setting up something like this:

( function( $ ) {
	$( document ).ready( function(){
		// Your code here

	});
})( jQuery );

You can use the jQuery change function to trigger some code when the checkboxes fields are checked (lien caché).

Writing such code is outside our support policy, I'm afraid, and the queue is too busy for me to go much further than the above advice.

Sorry I can't be more helpful.