Skip Navigation

[Resuelto] Conditional Display Using Checkbox Value and PHP

This support ticket is created hace 3 años, 6 meses. 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.

Este tema contiene 1 respuesta, tiene 1 mensaje.

Última actualización por julieP hace 3 años, 6 meses.

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