summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorM <m@lfurio.us>2015-12-05 21:37:03 -0500
committerM <m@lfurio.us>2015-12-05 21:37:03 -0500
commit9bab1e5c3d7dae9603c5f2172b2a620465caab0e (patch)
tree834d1b3ac14db59e922d234077912a814af931d4
parent91659b121e63735a7620663c0f43f5c5adef77d4 (diff)
downloadscrott-9bab1e5c3d7dae9603c5f2172b2a620465caab0e.tar.gz
scrott-9bab1e5c3d7dae9603c5f2172b2a620465caab0e.zip
* Form class fields now have the ability to set a default value. Default value is applied if the supplied $input array has no key matching the field name.
Diffstat (limited to '')
-rw-r--r--app/class/form.class.php38
1 files changed, 25 insertions, 13 deletions
diff --git a/app/class/form.class.php b/app/class/form.class.php
index 502e348..e50876d 100644
--- a/app/class/form.class.php
+++ b/app/class/form.class.php
@@ -28,21 +28,22 @@ class Form
/*
* Add new text field to the form
*/
- function field_text($name, $req = true)
+ function field_text($name, $deflt = null, $req = true)
{
if ($req !== true)
$req = false;
$this->textFields[] = array(
- 'name' => $name,
- 'req' => $req
+ 'name' => $name,
+ 'deflt' => $deflt,
+ 'req' => $req
);
}
/*
* Add new numeric field to the form
*/
- function field_numeric($name, $req = true, $integer = true, $min = null, $max = null)
+ function field_numeric($name, $min = null, $max = null, $deflt = null, $integer = true, $req = true)
{
if ($req !== true)
$req = false;
@@ -51,26 +52,28 @@ class Form
$integer = false;
$this->numbFields[] = array(
- 'name' => $name,
- 'req' => $req,
- 'int' => $integer,
- 'min' => $min,
- 'max' => $max
+ 'name' => $name,
+ 'min' => $min,
+ 'max' => $max,
+ 'deflt' => $deflt,
+ 'int' => $integer,
+ 'req' => $req
);
}
/*
* Add new enumeration field to the form
*/
- function field_enum($name, $req = true, $values)
+ function field_enum($name, $values, $deflt = null, $req = true)
{
if ($req !== true)
$req = false;
$this->enumFields[] = array(
- 'name' => $name,
- 'req' => $req,
- 'vals' => $values
+ 'name' => $name,
+ 'vals' => $values,
+ 'deflt' => $deflt,
+ 'req' => $req
);
}
@@ -100,6 +103,9 @@ class Form
if (isset($input[$fld['name']]))
$this->$fld['name'] = htmlEntities($input[$fld['name']], ENT_QUOTES);
+ else if (!is_null($fld['deflt']))
+ $this->$fld['name'] = $fld['deflt'];
+
else if ($fld['req'])
$this->logError($fld['name'] . " is required");
}
@@ -136,6 +142,9 @@ class Form
$this->$fld['name'] = $input[$fld['name']];
}
+ else if (!is_null($fld['deflt']))
+ $this->$fld['name'] = $fld['deflt'];
+
else if ($fld['req'])
$this->logError($fld['name'] . " is required");
}
@@ -154,6 +163,9 @@ class Form
$this->$fld['name'] = $input[$fld['name']];
}
+ else if (!is_null($fld['deflt']))
+ $this->$fld['name'] = $fld['deflt'];
+
else if ($fld['req'])
$this->logError($fld['name'] . " is required");
}