cvs: pear /DB_DataObject_FormBuilder FormBuilder.php
| From: | Justin Patrin | Date: | Fri, 27 May 2005 03:58:58 +0000 |
| Subject: | cvs: pear /DB_DataObject_FormBuilder FormBuilder.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-32149@lists.php.net to get a copy of this message | ||
justinpatrin Thu May 26 23:58:58 2005 EDT
Modified files:
/pear/DB_DataObject_FormBuilder FormBuilder.php
Log:
Only attempt to explode strings when set in an ini file (or in the static option array) and the
value is not __ALL__
Added fieldsRequired option, sets fields required which are allowed to be null, note: this removes
the automatic empty option for selects or enums which is usually added for nullalble fields
http://cvs.php.net/diff.php/pear/DB_DataObject_FormBuilder/FormBuilder.php?r1=1.179&r2=1.180&ty=u
Index: pear/DB_DataObject_FormBuilder/FormBuilder.php
diff -u pear/DB_DataObject_FormBuilder/FormBuilder.php:1.179
pear/DB_DataObject_FormBuilder/FormBuilder.php:1.180
--- pear/DB_DataObject_FormBuilder/FormBuilder.php:1.179 Thu May 26 19:35:29 2005
+++ pear/DB_DataObject_FormBuilder/FormBuilder.php Thu May 26 23:58:58 2005
@@ -94,7 +94,7 @@
* @author Justin Patrin <papercrane@reversefold.com>
* @copyright 1997-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version $Id: FormBuilder.php,v 1.179 2005/05/26 23:35:29 justinpatrin Exp $
+ * @version $Id: FormBuilder.php,v 1.180 2005/05/27 03:58:58 justinpatrin Exp $
* @link http://pear.php.net/package/DB_DataObject_FormBuilder
* @see DB_DataObject, HTML_QuickForm
*/
@@ -409,6 +409,12 @@
var $excludeFromAutoRules = array();
/**
+ * Array of fields which will be set required. This is in addition to all
+ * NOT NULL fields which are automatically set required.
+ */
+ var $fieldsRequired = array();
+
+ /**
* Array of groups to put certain elements in. The key is an element name, the
* value is the group to put the element in.
*/
@@ -881,10 +887,17 @@
// Read in config
$vars = get_object_vars($this);
+ $defVars = get_class_vars(get_class($this));
if (isset($GLOBALS['_DB_DATAOBJECT_FORMBUILDER']['CONFIG'])) {
//read all config options into member vars
foreach ($GLOBALS['_DB_DATAOBJECT_FORMBUILDER']['CONFIG'] as $key
=> $value) {
if (in_array($key, $vars) && $key[0] != '_') {
+ if ((!isset($defVars[$key])
+ || is_array($defVars[$key]))
+ && is_string($value)
+ && $value != '__ALL__') {
+ $value = $this->_explodeArrString($value);
+ }
$this->$key = $value;
}
}
@@ -896,15 +909,7 @@
$this->$key = $value;
}
}
- }
-
- $defVars = get_class_vars(get_class($this));
- foreach($defVars as $member => $value) {
- if (is_array($value) && isset($this->$member) &&
is_string($this->$member)) {
- $this->$member = $this->_explodeArrString($this->$member);
- }
- }
-
+ }
// Check whether we now got valid callbacks for some callback properties,
// otherwise correct them
foreach(array('dateFromDatabaseCallback', 'dateToDatabaseCallback',
'enumOptionsCallback') as $callback) {
@@ -1357,7 +1362,9 @@
}
$options = $newOptions;
}*/
- if (in_array($key, $this->selectAddEmpty) || !$notNull) {
+ if (in_array($key, $this->selectAddEmpty)
+ || (!$notNull
+ && !in_array($key, $this->fieldsRequired))) {
$options = array_merge(array('' =>
$this->selectAddEmptyLabel), $options);
}
if (!$options) {
@@ -1439,11 +1446,12 @@
//SET AUTO-RULES IF NOT DEACTIVATED FOR THIS OR ALL ELEMENTS
if ($this->excludeFromAutoRules != '__ALL__' && !in_array($key,
$this->excludeFromAutoRules)) {
//ADD REQURED RULE FOR NOT_NULL FIELDS
- if ((!in_array($key, $keys) || $this->hidePrimaryKey == false)
+ if ((!in_array($key, $keys)
+ || $this->hidePrimaryKey == false)
&& ($notNull)
&& !in_array($key, $elements_to_freeze)
- && !($type & DB_DATAOBJECT_BOOL)) {
-
+ && !($type & DB_DATAOBJECT_BOOL)
+ || in_array($key, $this->fieldsRequired)) {
$this->_form->_setFormElementRequired($key);
$this->debug('Adding required rule for '.$key);
}