Skip Navigation

[Résolu] Conditional Display Using Checkbox Value and PHP

This support ticket is created Il y a 3 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.

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

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

Auteur
Publications
#2065421

I have a Checkboxes field with options 1 and 2 and set to save nothing if unchecked. I can display the checked values using types_render_field() but my code to display content based on the value(s) saved for the field isn't generating the correct output. This is my code:-

$option1 = 'A';
                    $option2 = 'B';  
                    $values = types_render_field( "apply-to-list", array("post_id" => '20', "separator" => ", " ) );                     
                    $values_arr = explode(', ', $values);
                     
                    if (in_array($option1, $values_arr) && in_array($option2, $values_arr)) {
                        echo '<p>A and B</p>';
                    } else if (in_array($option1, $values_arr) && !in_array($option2, $values_arr)) {
                        echo '<p>A</p>';
                    } else if (!in_array($option1, $values_arr) && in_array($option2, $values_arr)) {
                        echo '<p>B</p>';
                    } else {
                        echo '<p>Neither A nor B</p>';
                    }

The uploaded image shows the value in the database is A but the output on the page is "Neither A nor B".

Any ideas please?

#2065425

I discovered the values to check against are the checkbox title not the value saved to the database