diff --git a/gulliver/system/class.form.php b/gulliver/system/class.form.php
index d11e493fc..a8150de12 100755
--- a/gulliver/system/class.form.php
+++ b/gulliver/system/class.form.php
@@ -61,19 +61,43 @@ class Form extends XmlForm
* @access public
* @return string
*/
+
public function setDefaultValues ()
{
foreach ($this->fields as $name => $content) {
if (is_object( $content ) && get_class( $content ) != '__PHP_Incomplete_Class') {
if (isset( $content->defaultValue )) {
- $this->values[$name] = $content->defaultValue;
+ switch ($content->type) {
+ case "checkgroup":
+ case "listbox":
+ $defaultValueAux = trim($content->defaultValue);
+
+ if ($defaultValueAux != "") {
+ $this->values[$name] = $content->defaultValue;
+ } else {
+ $this->values[$name] = "__NULL__";
+ }
+ break;
+ default:
+ $this->values[$name] = $content->defaultValue;
+ break;
+ }
} else {
- $this->values[$name] = '';
+ switch ($content->type) {
+ case "checkgroup":
+ case "listbox":
+ $this->values[$name] = "__NULL__";
+ break;
+ default:
+ $this->values[$name] = "";
+ break;
+ }
}
} else {
$this->values[$name] = '';
}
}
+
foreach ($this->fields as $k => $v) {
if (is_object( $v )) {
//julichu
@@ -117,6 +141,7 @@ class Form extends XmlForm
trigger_error( 'Faild to create cache file "' . $xmlform->parsedFile . '".', E_USER_ERROR );
}
$this->setDefaultValues();
+
//to do: review if you can use the same form twice. in order to use once or not.
//DONE: Use require to be able to use the same xmlform more than once.
foreach ($this->fields as $k => $v) {
@@ -229,6 +254,7 @@ class Form extends XmlForm
if (! is_array( $newValues )) {
return;
}
+
foreach ($this->fields as $k => $v) {
if (array_key_exists( $k, $newValues )) {
if (is_array( $newValues[$k] )) {
@@ -362,9 +388,9 @@ class Form extends XmlForm
$values[$k] = $values[$k . "_label"] = null;
foreach ($newValues[$k] as $i => $value) {
//if $value is empty continue with the next loop, because this is a not selected/checked item
- if (trim( $value ) == '') {
- continue;
- }
+ //if (trim( $value ) == '') {
+ // continue;
+ //}
$values[$k] .= (($i != 0) ? "|" : null) . $value;
@@ -510,8 +536,13 @@ class Form extends XmlForm
}
}
} else {
- if ($v->type == 'checkgroup') {
- $values[$k] = null;
+ switch ($v->type) {
+ case "checkgroup":
+ case "listbox":
+ //This value is added when the user does not mark any checkbox
+ $values[$k . "_label"] = "__NULL__";
+ $values[$k] = "__NULL__";
+ break;
}
}
} else {
diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php
index be26b67e0..c399a06a0 100755
--- a/gulliver/system/class.xmlform.php
+++ b/gulliver/system/class.xmlform.php
@@ -3599,6 +3599,15 @@ class XmlForm_Field_Listbox extends XmlForm_Field
if (! is_array( $value )) {
$value = explode( '|', $value );
}
+
+ $arrayAux = array();
+
+ foreach ($value as $index2 => $value2) {
+ $arrayAux[] = $value2 . "";
+ }
+
+ $value = $arrayAux;
+
if ($this->mode === 'edit') {
$itemWidth = '';
if ($this->width != '') {
@@ -3606,10 +3615,10 @@ class XmlForm_Field_Listbox extends XmlForm_Field
}
$html = '';
@@ -3618,17 +3627,17 @@ class XmlForm_Field_Listbox extends XmlForm_Field
} elseif ($this->mode === 'view') {
$html = '';
foreach ($this->option as $optionName => $option) {
- $html .= '';
+ $html .= "name . "]\" name=\"form[" . $this->name . "][]\" value=\"" . ((in_array( $optionName . "", $value )) ? $optionName : "__NULL__") . "\">";
}
foreach ($this->sqlOption as $optionName => $option) {
- $html .= '';
+ $html .= "name . "]\" name=\"form[" . $this->name . "][]\" value=\"" . ((in_array( $optionName . "", $value )) ? $optionName : "__NULL__") . "\">";
}
return $html;
} else {
@@ -3802,20 +3811,20 @@ class XmlForm_Field_CheckGroup extends XmlForm_Field
if (! is_array( $value )) {
$value = explode( '|', $value );
}
+
+ $arrayAux = array();
+
+ foreach ($value as $index2 => $value2) {
+ $arrayAux[] = $value2 . "";
+ }
+
+ $value = $arrayAux;
+
if ($this->mode === 'edit') {
$i = 0;
$html = '';
foreach ($this->options as $optionName => $option) {
- $swCheked = 0;
-
- foreach ($value as $index2 => $value2) {
- if (strlen($value2 . "") > 0 && $value2 == $optionName) {
- $swCheked = 1;
- break;
- }
- }
-
- $html = $html . "name . "][" . $optionName . "]\" name=\"form[" . $this->name . "][]\" value=\"" . $optionName . "\"" . (($swCheked == 1) ? " checked=\"checked\" " : "") . ">";
+ $html .= "name . "][" . $optionName . "]\" name=\"form[" . $this->name . "][]\" value=\"" . $optionName . "\"" . (in_array( $optionName . "", $value ) ? "checked = \"checked\" " : "") . ">";
if (++ $i == count( $this->options )) {
$html .= ' ' . $this->renderHint();
@@ -3826,17 +3835,8 @@ class XmlForm_Field_CheckGroup extends XmlForm_Field
} elseif ($this->mode === 'view') {
$html = '';
foreach ($this->options as $optionName => $option) {
- $swCheked = 0;
-
- foreach ($value as $index2 => $value2) {
- if (strlen($value2 . "") > 0 && $value2 == $optionName) {
- $swCheked = 1;
- break;
- }
- }
-
- $html = $html . "name . "][" . $optionName . "]\" value=\"" . $optionName . "\"" . (($swCheked == 1) ? " checked=\"checked\" " : "") . " disabled=\"disabled\">
";
- $html = $html . "name . "][]\" value=\"" . (($swCheked == 1) ? $optionName : "") . "\">";
+ $html .= "name . "][" . $optionName . "]\" value=\"" . $optionName . "\"" . (in_array( $optionName . "", $value ) ? " checked=\"checked\" " : "") . " disabled=\"disabled\">
";
+ $html .= "name . "][]\" value=\"" . ((in_array( $optionName . "", $value )) ? $optionName : "__NULL__") . "\">";
}
return $html;
} else {