Forum

Thread tagged as: Question, Problem, Api

Settings API

I am having some issues with adding a setting using the Perch API.

$this->add_setting('ui_checkout_billing_address', 'Collect Billing Information', 'checkbox',  'true', true );
$this->add_setting('ui_checkout_shipping_address', 'Collect Shipping Information', 'checkbox', 'false', false );

I have tried a bunch of different things but I still keep getting the same results. I try to set one of the check boxes to true or false but it always just shows ="1" as the value. Am I doing something wrong? I would like the value to say "true" if checked if not have it say "false" is that possible withing this setting area of the API?

Brandon Livengood

Brandon Livengood 1 points

  • 6 years ago

Brandon Livengood said:

I am having some issues with adding a setting using the Perch API.

$this->add_setting('ui_checkout_billing_address', 'Collect Billing Information', 'checkbox', 'true', true ); $this->add_setting('ui_checkout_shipping_address', 'Collect Shipping Information', 'checkbox', 'false', false );

I have tried a bunch of different things but I still keep getting the same results. I try to set one of the check boxes to true or false but it always just shows ="1" as the value. Am I doing something wrong? I would like the value to say "true" if checked if not have it say "false" is that possible withing this setting area of the API?

Brandon, I had this issue the other day. Ended up having to use a select field. Any value on a checkbox is true even if you put false as the value.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Checkboxes are binary. You can't have strings 'true' and 'false' because both of those are true to PHP.

Gotcha I figured out a solution thanks.