6.0.0-beta1
10/16/25

[#11308] Horde_Form_Type_boolean does not accept direct true or false values
Summary Horde_Form_Type_boolean does not accept direct true or false values
Queue Horde Framework Packages
Queue Version Git master
Type Enhancement
State Resolved
Priority 1. Low
Owners jan (at) horde (dot) org
Requester lfbm.andamentos (at) gmail (dot) com
Created 07/23/2012 (4833 days ago)
Due
Updated 08/29/2012 (4796 days ago)
Assigned
Resolved 08/07/2012 (4818 days ago)
Milestone
Patch Yes

History
08/29/2012 12:46:31 PM Git Commit Comment #8 Reply to this comment
Changes have been made in Git (master):

commit 5e1ee9cda6b078839da2a24348b8198b5c8a9064
Author: dulinux <lfbm.andamentos@gmail.com>
Date:   Sun Jul 22 23:39:50 2012 -0300

     Allow Horde_Form_Type_boolean to accept hidden true or false values

     Request: 11308
     Signed-off-by: Jan Schneider <jan@horde.org>

  framework/Form/lib/Horde/Form/Type.php |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

http://git.horde.org/horde-git/-/commit/5e1ee9cda6b078839da2a24348b8198b5c8a9064
08/08/2012 12:52:35 AM lfbm (dot) andamentos (at) gmail (dot) com Comment #7 Reply to this comment
Sure, that was precisely the case. Thanks for taking the time to review this.

08/07/2012 12:56:54 PM Jan Schneider Comment #6
Assigned to Jan Schneider
State ⇒ Resolved
Reply to this comment
So the idea *was* to only trigger this when setting the value 
manually. Makes sense.
08/07/2012 12:56:18 PM Git Commit Comment #5 Reply to this comment
Changes have been made in Git (develop):

commit 5e1ee9cda6b078839da2a24348b8198b5c8a9064
Author: dulinux <lfbm.andamentos@gmail.com>
Date:   Sun Jul 22 23:39:50 2012 -0300

     Allow Horde_Form_Type_boolean to accept hidden true or false values

     Request: 11308
     Signed-off-by: Jan Schneider <jan@horde.org>

  framework/Form/lib/Horde/Form/Type.php |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

http://git.horde.org/horde-git/-/commit/5e1ee9cda6b078839da2a24348b8198b5c8a9064
08/07/2012 12:55:16 PM Git Commit Comment #4 Reply to this comment
Changes have been made in Git (FRAMEWORK_4):

commit 92f0404567865aa623ac5842c8fdeba48d225460
Author: dulinux <lfbm.andamentos@gmail.com>
Date:   Sun Jul 22 23:39:50 2012 -0300

     Allow Horde_Form_Type_boolean to accept hidden true or false values

     Request: 11308
     Signed-off-by: Jan Schneider <jan@horde.org>

  framework/Form/lib/Horde/Form/Type.php |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

http://git.horde.org/horde-git/-/commit/92f0404567865aa623ac5842c8fdeba48d225460
08/06/2012 10:36:52 PM lfbm (dot) andamentos (at) gmail (dot) com Comment #3 Reply to this comment
unless you explicitly set the value to true/false, i.e. you don't 
get the value from a submitted form.
Yes, that´s exactly the hypothesis I have in mind. Suppose you have a 
hidden boolean form type that is set explicitly based on some 
condition and you want this variable to survive a reload action. 
Unless you explicitly set it as "on", it won´t work when, at last, you 
process the result from getInfo. The trouble here is that it´s 
unintuitive to explicitly set a form variable of the boolean type as 
"on" instead of true or false.

For example, see the code below. Probably not the best code (maybe 
should be separated in more subclasses, but it´s still a mockup), but 
this is why I came upon this matter:

class Cashier_Form_Transaction extends Horde_Form
{
     public function __construct($vars, $title)
     {
         parent::__construct($vars, $title);

         $this->addHidden('', 'actionID', 'text', false, false, null);
         $this->addHidden('', 'transaction_is_credit', 'boolean', 
false, false, null);
         $this->addHidden('', 'transaction_is_income', 'boolean', 
false, false, null);

         switch ($vars->get('actionID')) {
             case 'money_in':
                 /* This variable will be translated to (bool)true in 
the end. */
                 $this->_vars->transaction_is_income = 'on';
                 $trans_types = array(
                     'invoice' => _('Invoice'),
                     'deposit' => _('Deposit')
                 );

                 if (!isset($this->_vars->trans_type)){
                     $this->_vars->trans_type = 'invoice';
                 }

                 break;
             case 'money_out':
                 $this->_vars->transaction_is_income = 'off';
                 $trans_types = array(
                     'bill' => _('Bill'),
                     'payment' => _('Payment')
                 );

                 if (!isset($this->_vars->trans_type)){
                     $this->_vars->trans_type = 'bill';
                 }

                 break;
         }

         $trans_type_enum = $this->addVariable(_('Type'), 
'trans_type', 'enum', true, false, null, array($trans_types, true));
         $trans_type_enum->setAction(Horde_Form_Action::factory('reload'));

         switch ($this->_vars->trans_type) {
             case 'invoice':
                 $tdhn = _('Dua date');
                 $this->_vars->transaction_is_credit = 'off';
                 break;
             case 'payment':
                 $tdhn = _('Date');
                 $this->_vars->transaction_is_credit = 'off';
                 break;
             case 'deposit':
                 $tdhn = _('Date');
                 $this->_vars->transaction_is_credit = 'on';
                 break;
             case 'bill':
                 $tdhn = _('Dua date');
                 $this->_vars->transaction_is_credit = 'on';
                 break;
         }

         $this->addVariable(_('Account'), 'transaction_owner', 'enum', 
true, false, null, array(Cashier::listAccounts(false, 
Horde_Perms::EDIT, true), 
true))->setDefault(Cashier::getDefaultAccount());

         $clients = Cashier::listClients();
         foreach ($clients as $id => $name) {
                 $client_enum[$id] = $name;
         }

         $this->addVariable(_('Client'), 'client_id', 'enum', true, 
false, null, array($client_enum, true));

         $this->addVariable(_('Value'), 'transaction_value', 'int', 
true, false, null);
         $this->addVariable(_($tdhn), 'transaction_date', 
'monthdayyear', true, false, null, array())->setDefault(date('Y-m-d'));
         $this->addVariable(_('Description'), 'transaction_desc', 
'text', false, false, null, array(null, 60, 60));

         if ($this->_vars->trans_type == 'invoice' || 
$this->_vars->trans_type == 'bill') {
             $this->addVariable(_('Is it paid?'), 'is_paid', 
'boolean', false, false, null);
             $this->addVariable(_('Date paid'), 'date_paid', 
'monthdayyear', false, false, null, array());
         } else {
             $this->addHidden('', 'is_paid', 'boolean', false, false, null);
         }

         $this->setButtons(array(_('Save'), _('Cancel')));
     }
}

I´m explicitly setting some hidden boolean variables to "on" or "off", 
as a way of making it work as expected, since only the string 'on' 
will evaluate to true when I call the getInfo method later. But I 
think it would be more intuitive if one could set this kind of 
variable to true or false, hence my suggestion.
08/06/2012 08:11:05 PM Jan Schneider Comment #2
State ⇒ Feedback
Reply to this comment
How is that supposed to work. A submitted form field, whether hidden 
or visible, is always passing a string. is_bool() is always false, 
unless you explicitly set the value to true/false, i.e. you don't get 
the value from a submitted form.
07/23/2012 02:58:05 AM lfbm (dot) andamentos (at) gmail (dot) com Comment #1
Priority ⇒ 1. Low
Type ⇒ Enhancement
Summary ⇒ Horde_Form_Type_boolean does not accept direct true or false values
Queue ⇒ Horde Framework Packages
Milestone ⇒
Patch ⇒ Yes
New Attachment: 0001-Allow-Horde_Form_Type_boolean-to-accept-hidden-true-.patch Download
State ⇒ New
Reply to this comment
getInfo method of Horde_Form_Type_boolean will only properly work with 
'on' as variable value. So it will fail if you wish to work with 
hidden variables that are directly set as (bool)true or (bool)false in 
your form.

For example, if you create a hidden variable of the type 'boolean' in 
your form, you can´t manually assign to it a value of (bool)true, 
because the getInfo method, once called, will say the variable is 
false (since it´s not equal to 'on' in the getInfo method).

The consequence is this type will only work as expected for visible 
variables in the form. For hidden variables, you should manually 
assign the string 'on' when you want it to evaluate as true, which is 
unintuitive, since it is a boolean type, so you should be able to 
simply set the hidden variable to 'true' of 'false', instead of 'on' 
or not setting the variable.

So I guess the getInfo method of this type should first check if the 
variable value is already a boolean and then return it. In case it 
isn´t a boolean, then it should check if it´s equal to 'on' and 
evaluate properly, as it already does.

Attached is my suggestion.

Saved Queries