← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1816: [form] Cast choice control values to strings when filling

 

------------------------------------------------------------
revno: 1816
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt
timestamp: Thu 2011-03-17 15:03:28 +0100
message:
  [form] Cast choice control values to strings when filling
  
  Make sure choice controls are always filled with string
  values. Before this change AnewtFormControlChoice
  incorrectly enabled an option with a "" value when the form
  was filled with the integer 0 value (even if the choice
  control also contained an option with a "0" value). This is
  especially problematic in combination with the recently
  introduced null-value support.
modified:
  form/controls/choice.lib.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription
=== modified file 'form/controls/choice.lib.php'
--- form/controls/choice.lib.php	2011-03-17 13:39:30 +0000
+++ form/controls/choice.lib.php	2011-03-17 14:03:28 +0000
@@ -206,9 +206,12 @@
 		if ($this->_get('disabled'))       return true;
 
 		/* If none of the values in the choice control are selected, there is no
-		 * value for this control in $values (just like for checkboxes). */
+		 * value for this control in $values (just like for checkboxes). Make
+		 * sure the value is a string so that we don't hit "empty string equals
+		 * integer 0" comparison issues when filling from e.g. database records
+		 * containing real integer values. */
 		$name = $this->get('name');
-		$value = array_get_default($values, $name, null);
+		$value = (string) array_get_default($values, $name, null);
 		parent::fill(array($name => $value));
 
 		/* Filling succeeds if... */