Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Request #19403: do not return values for internal fields

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_QuickForm2/trunk@325701 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 09c1378bb5956b2520d98b58b23cbd12be1f5fbc 1 parent 9baf1a3
@sad-spirit sad-spirit authored
View
19 HTML/QuickForm2.php
@@ -114,6 +114,7 @@ public function __construct(
'hidden', '_qf__' . $id, array('id' => 'qf:' . $id)
));
}
+ $this->addFilter(array($this, 'skipInternalFields'));
}
protected function onAttributeChange($name, $value = null)
@@ -234,5 +235,23 @@ public function render(HTML_QuickForm2_Renderer $renderer)
$renderer->finishForm($this);
return $renderer;
}
+
+ /**
+ * Filter for form's getValue() removing internal fields' values from the array
+ *
+ * @param array $value
+ *
+ * @return array
+ * @link http://pear.php.net/bugs/bug.php?id=19403
+ */
+ protected function skipInternalFields($value)
+ {
+ foreach (array_keys($value) as $key) {
+ if ('_qf' === substr($key, 0, 3)) {
+ unset($value[$key]);
+ }
+ }
+ return $value;
+ }
}
?>
View
2  HTML/QuickForm2/Container.php
@@ -213,7 +213,7 @@ public function getValue()
*
* @return array resulting array
*/
- protected static function arrayMerge($a, $b)
+ public static function arrayMerge($a, $b)
{
foreach ($b as $k => $v) {
if (!is_array($v) || isset($a[$k]) && !is_array($a[$k])) {
View
37 HTML/QuickForm2/Controller.php
@@ -468,45 +468,14 @@ public function getValue()
{
$values = array();
foreach (array_keys($this->pages) as $id) {
- $pageValues = $this->getSessionContainer()->getValues($id);
- // skip elements representing actions
- foreach ($pageValues as $key => $value) {
- if (0 !== strpos($key, '_qf')) {
- if (isset($values[$key]) && is_array($value)) {
- $values[$key] = self::arrayMerge($values[$key], $value);
- } else {
- $values[$key] = $value;
- }
- }
- }
+ $values = HTML_QuickForm2_Container::arrayMerge(
+ $values, $this->getSessionContainer()->getValues($id)
+ );
}
return $values;
}
/**
- * Merges two arrays
- *
- * Merges two arrays like the PHP function array_merge_recursive does,
- * the difference being that existing integer keys will not be renumbered.
- *
- * @param array $a
- * @param array $b
- *
- * @return array resulting array
- */
- protected static function arrayMerge($a, $b)
- {
- foreach ($b as $k => $v) {
- if (!is_array($v) || isset($a[$k]) && !is_array($a[$k])) {
- $a[$k] = $v;
- } else {
- $a[$k] = self::arrayMerge(isset($a[$k])? $a[$k]: array(), $v);
- }
- }
- return $a;
- }
-
- /**
* Returns an Iterator for the form's pages
*
* @return ArrayIterator
View
13 tests/QuickForm2Test.php
@@ -189,5 +189,18 @@ public function testFormRule()
$this->assertFalse($form->validate());
$this->assertEquals('an error message', $foo->getError());
}
+
+ /**
+ * Do not return values for automatically added elements from getValue()
+ * @link http://pear.php.net/bugs/bug.php?id=19403
+ */
+ public function testRequest19403()
+ {
+ $_POST = array('_qf__track' => '');
+ $form = new HTML_QuickForm2('track');
+
+ $this->assertArrayHasKey('_qf__track', $form->getRawValue());
+ $this->assertArrayNotHasKey('_qf__track', $form->getValue());
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.