From: uw
Date: Sun May 13 17:52:57 2001
Modified files:
php-lib/php/form/form.inc
php-lib/php/form/form_xmlfactory.inc
php-lib/php/form/xml/form.xml
Log message:
- finished the work on the xml format
Index: php-lib/php/form/form.inc
diff -u php-lib/php/form/form.inc:1.26 php-lib/php/form/form.inc:1.27
--- php-lib/php/form/form.inc:1.26 Fri May 11 22:53:16 2001
+++ php-lib/php/form/form.inc Sun May 13 17:52:55 2001
@@ -28,7 +28,7 @@
* - tree (select box with options show as a tree)
*
* @author Ulf Wendel <[EMAIL PROTECTED]>
-* @version $Id: form.inc,v 1.26 2001/05/11 20:53:16 uw Exp $
+* @version $Id: form.inc,v 1.27 2001/05/13 15:52:55 uw Exp $
* @access public
* @package Form
*/
@@ -448,7 +448,7 @@
*/
function getStart() {
- $html = sprintf('<form action="%s" target="%s" method = "%s"',
+ $html = sprintf('<form action="%s" target="%s" method = "%s" ',
$this->action,
$this->target,
$this->method
@@ -570,12 +570,10 @@
$element_data["name"] = $this->element_prefix .
$element_data["name"];
$element_data["type"] = strtolower($element_data["type"]);
-
- $objectname = "form_element_" . $element_data["type"];
- include_once(FORM_INCLUDE_DIR . "/elements/" . $objectname . ".inc");
-
$this->addDefaultAttributes($element_data);
-
+
+ $objectname = "form_element_" . $element_data["type"];
+ include_once(FORM_INCLUDE_DIR . 'elements/' . $objectname . '.inc');
$el = new $objectname($element_data, $this->method,
$this->js_name, $this->js_mode);
if ($el->isHidden())
@@ -868,7 +866,7 @@
$file = ($complex = count($validators)) ? "form_js_complex.js" :
"form_js_simple.js";
// get the code
- $file = FORM_INCLUDE_DIR . $file;
+ $file = FORM_INCLUDE_DIR . '/js/' . $file;
$fh = fopen($file, "r");
if (!$fh) {
$this->exceptions[] = new form_error("Can't read JavaScript
code file: '$file'.", __FILE__, __LINE__);
Index: php-lib/php/form/form_xmlfactory.inc
diff -u php-lib/php/form/form_xmlfactory.inc:1.2
php-lib/php/form/form_xmlfactory.inc:1.3
--- php-lib/php/form/form_xmlfactory.inc:1.2 Fri May 11 22:53:16 2001
+++ php-lib/php/form/form_xmlfactory.inc Sun May 13 17:52:56 2001
@@ -99,15 +99,43 @@
* @var string
*/
var $name = "";
+
+ /**
+ * Form default values
+ *
+ * @var array
+ */
+ var $defaults;
+
+ /**
+ * Form JS error message prefix
+ *
+ * @var string
+ */
+ var $js_error_prefix = "";
/**
+ * Form JS error message postfix
+ *
+ * @var string
+ */
+ var $js_error_postfix = "";
+
+
+ /**
* Name of the currently processed tag
*
* @var string
*/
var $current_tag = "";
+ /**
+ * Parser flag if the outer container is defaults
+ *
+ * @var boolean
+ */
+ var $flag_defaults = false;
/**
* Returns a form object build from the given xml file.
@@ -117,13 +145,25 @@
* @return mixed object form on success, otherwise false
*/
function form_xmlfactory($file) {
-
if (!($xml = implode("", file($file)))) {
$this->throw = new form_error("Can't read XML file '$file'.");
return false;
}
+
+
+ $this->defaults = array();
+ $this->attributes = array();
+ $this->intros = array();
+ $this->validation = array();
+
$this->parse($xml);
+ if (!empty($this->defaults))
+ $this->form->setDefaults($this->defaults);
+
+ if ("" != $this->js_error_prefix || "" != $this->js_error_postfix)
+ $this->form->setJSError($this->js_error_prefix, $this->js_error_postfix);
+ // Hmm, Hack?
$this = $this->form;
} // end constructor
@@ -155,10 +195,15 @@
function startElement($parser, $name, $attrs) {
$this->current_tag = $name = strtolower($name);
-
+
+ if ("defaults" == $name)
+ $this->flag_defaults = true;
+ else if ("elements" == $name)
+ $this->flag_defaults = false;
+
$tmp = array();
foreach ($attrs as $k => $v) {
-
+
$k = strtolower($k);
switch ($k) {
@@ -211,15 +256,66 @@
case "text":
case "textarea":
case "textedit":
- $this->attributes = $attrs;
- $this->attributes["type"] = $name;
+
+ if (!$this->flag_defaults) {
+ // plain element
+ $this->attributes = $attrs;
+ $this->attributes["type"] = $name;
+
+ } else {
+
+ // global form defaults
+ switch ($name) {
+ case "file":
+ if (isset($attrs["size"]))
+ $this->defaults["filesize"] = (int)$attrs["size"];#
+ break;
+
+ case "image":
+ if (isset($attrs["border"]))
+ $this->defaults["imageborder"] = (int)$attrs["size"];
+ break;
+
+ case "text":
+ if (isset($attrs["size"]))
+ $this->defaults["textsize"] = (int)$attrs["size"];
+ if (isset($attrs["maxlength"]))
+ $this->defaults["textmaxlength"] = (int)$attrs["maxlength"];
+ break;
+ }
+
+ } // end if !$this->flag_defaults
break;
+ case "javascript":
+ if (isset($attrs["mode"]))
+ $this->form->setJSMode((string)$attrs["mode"]);
+ break;
+
+ case "elements":
+ if (isset($attrs["nameprefix"]))
+ $this->form->setElementnamePrefix((string)$attrs["nameprefix"]);
+ break;
+
case "css":
- if (isset($attrs["class"]))
- $this->attributes["class"] = (string)$attrs["class"];
- if (isset($attrs["id"]))
- $this->attributes["id"] = (string)$attrs["id"];
+ if (!$this->flag_defaults) {
+
+ // plain element
+ if (isset($attrs["class"]))
+ $this->attributes["class"] = (string)$attrs["class"];
+ if (isset($attrs["id"]))
+ $this->attributes["id"] = (string)$attrs["id"];
+
+ } else {
+
+ // global form defaults
+ if (isset($attrs["class"]))
+ $this->defaults["cssclass"] = (string)$attrs["class"];
+ if (isset($attrs["id"]))
+ $this->defaults["cssid"] = (string)$attrs["id"];
+ }
+
+
break;
case "html":
@@ -302,7 +398,7 @@
* @param string tag name
*/
function endElement($parser, $name) {
-
+
$name = strtolower($name);
switch ($name) {
@@ -311,7 +407,15 @@
case "year":
$this->attributes[$name] = (int)$this->cdata;
break;
+
+ case "errorprefix":
+ $this->js_error_prefix = (string)$this->cdata;
+ break;
+ case "errorpostfix":
+ $this->js_error_postfix = (string)$this->cdata;
+ break;
+
case "phpfunction":
$this->attributes["validator"] = (string)$this->cdata;
break;
@@ -321,7 +425,11 @@
break;
case "css":
- $this->attributes["style"] = (string)$this->cdata;
+ if (!$this->flag_defaults)
+ $this->attributes["style"] = (string)$this->cdata;
+ else
+ $this->defaults["cssstyle"] = (string)$this->cdata;
+
break;
case "html":
@@ -329,11 +437,19 @@
break;
case "intro":
- $this->attributes["intro"] = array($this->attrs["value"] =>
(string)$this->cdata);
+ if (!$this->flag_defaults)
+ $this->attributes["intro"] = array($this->attrs["value"] =>
+(string)$this->cdata);
+ else
+ $this->defaults["selectintro"] = array($this->attrs["value"] =>
+(string)$this->cdata);
+
break;
case "intros":
- $this->attributes["intro_e"] = (string)$this->intros["errormsg"];
+ if (!$this->flag_defaults)
+ $this->attributes["intro_e"] = (string)$this->intros["errormsg"];
+ else
+ $this->defaults["selectintro_e"] = (string)$this->intros["errormsg"];
+
break;
case "option":
@@ -368,13 +484,14 @@
case "text":
case "textarea":
case "textedit":
- $this->form->addElement($this->attributes);
+ if (!$this->flag_defaults)
+ $this->form->addElement($this->attributes);
break;
default:
break;
}
-
+
} // end func endElement
Index: php-lib/php/form/xml/form.xml
diff -u php-lib/php/form/xml/form.xml:1.3 php-lib/php/form/xml/form.xml:1.4
--- php-lib/php/form/xml/form.xml:1.3 Fri May 11 22:53:18 2001
+++ php-lib/php/form/xml/form.xml Sun May 13 17:52:56 2001
@@ -1,205 +1,215 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form SYSTEM "C:\www\apache\form\form.dtd">
-<form jsname="" method="POST" action="" target="" name="">
- <additionalhtml/>
-
- <javascript>
- <mode>weak or strong</mode>
+<form method="POST" action="test.php" target="self" name="form1" jsname="jsname">
+
+ <javascript mode="weak">
+ <errorprefix>There're errors in the form: \n\n</errorprefix>
+ <errorpostfix>\n\nPlease correct the input.</errorpostfix>
</javascript>
-
- <elements>
- <nameprefix>prefix_</nameprefix>
- </elements>
-
- <calendar name="calendar" elname="calendar" frozen="false" minyear="" maxyear=""
now="" prev="" next="">
- <preselect>
- <day></day>
- <month></month>
- <year></year>
- </preselect>
- <css class="css class" id="id">style</css>
- <html>additional html</html>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </calendar>
-
- <checkbox name="checkbox" elname="checkbox" frozen="false" checked="false">
- value
- <css class="css class" id="id">style</css>
- <html accesskey="" tabindex="">additional html</html>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </checkbox>
-
- <combo name="combo" elname="combo" inputsize="1" readonly="false" sort=""
frozen="false" add="true" size="1">
- value
- <options>
- <option value=""/>
- </options>
- <intros errormsg = "error">
- <intro value="">intro</intro>
- </intros>
- <validation>
- <length min="0" max="-1">length_e</length>
- <regexp reg="" icase="false">valid_e</regexp>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- <css class="css class" id="id">style</css>
- <html accesskey="" tabindex="">additional html</html>
- </combo>
-
- <date name="date" elname="date" language="en" frozen="false" preload="false"
format="d.m.Y" now="jetzt" intro="" intro_e="">
- value
- <limits>
- <yearlong min="1990" max="-1"/>
- <yearshort min="90" max="-1"/>
- </limits>
- <html>additional html</html>
- <css class="css class" id="id">style</css>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </date>
-
- <file size="1" accept="" name="file" elname="file" frozen="false">
- value
- <html accesskey="" tabindex="">additional html</html>
- <css class="css class" id="id">style</css>
- <validation>
- <length min="0" max="1">length_e</length>
- <regexp reg="" icase="false">valid_e</regexp>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </file>
-
- <fileupload size="1" maxfilesize="100" accept="" name="fileupload"
elname="fileupload" frozen="false">
- value
- <html accesskey="" tabindex="">additional html</html>
- <css class="css class" id="id">style</css>
- <validation>
- <length min="0" max="1">length_e</length>
- <regexp reg="" icase="false">valid_e</regexp>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </fileupload>
-
- <hidden name="hidden" elname="hidden" frozen="false">
- value
- <html>additional html</html>
- <css class="css class" id="id">style</css>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </hidden>
-
- <image name="image" elname="image" align="" alt="" hspace="1" vspace="1" border="1"
width="1" height="1" usemap="" frozen="false">
- src
- <html accesskey="" tabindex="">additional html</html>
- <css class="css class" id="id">style</css>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </image>
-
- <password name="password" elname="password" size="-1" readonly="false"
frozen="false">
- value
- <css class="css class" id="id">style</css>
- <html accesskey="" tabindex="">additional html</html>
- <validation>
- <length min="0" max="-1">length_e</length>
- <regexp reg="" icase="false">valid_e</regexp>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </password>
-
- <radio name="radio" elname="radio" checked="false" frozen="false">
- value
- <css class="css class" id="id">style</css>
- <html accesskey="" tabindex="">additional html</html>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </radio>
-
- <reset name="reset" elname="reset" frozen="false" width="1" height="1">
- <css class="css class" id="id">style</css>
- <html accesskey="" tabindex="">additional html</html>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </reset>
-
- <select name="select" elname="select" frozen="false" size="0" multiple="false">
- value
- <options>
- <option value=""/>
- </options>
- <intros errormsg="error">
- <intro value="">intro</intro>
+
+ <defaults>
+ <text size="0" maxlength="0"/>
+ <file size="0"/>
+ <image border="0"/>
+ <intros errormsg = "Don't select me">
+ <intro value="0">intro</intro>
</intros>
- <html accesskey="" tabindex="">additional html</html>
- <css class="css class" id="id">style</css>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </select>
-
- <submit name="submit" elname="submit" width="1" height="1" frozen="false"
accesskey="" tabindex="">
- value
- <html accesskey="" tabindex="">additional html</html>
<css class="css class" id="id">style</css>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </submit>
+ </defaults>
- <text name="text" elname="text" size="-1" readonly="false" frozen="false">
- value
- <css class="css class" id="id">style</css>
- <html accesskey="" tabindex="">additional html</html>
- <validation>
- <length min="0" max="-1">length_e</length>
- <regexp reg="" icase="false">valid_e</regexp>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </text>
-
- <textarea name="textarea" elname="textarea" rows="1" cols="1" wrap="virtual"
readonly="false" frozen="false">
- value
- <css class="css class" id="id">style</css>
- <html accesskey="" tabindex="">additional html</html>
- <validation>
- <length min="0" max="-1">length_e</length>
- <regexp reg="" icase="false" global="false">valid_e</regexp>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </textarea>
-
- <textedit name="textedit" elname="textedit" frozen="false">
- value
- <css class="css class" id="id">style</css>
- <html accesskey="" tabindex="">additional html</html>
- <validation>
- <phpfunction></phpfunction>
- <jsfunction></jsfunction>
- </validation>
- </textedit>
+ <elements nameprefix="prefix_">
+
+ <calendar name="calendar" elname="calendar" frozen="false" minyear="2000"
+maxyear="2010" now="today" prev="<<" next=">>">
+ <preselect>
+ <day>1</day>
+ <month>5</month>
+ <year>2001</year>
+ </preselect>
+ <css class="css class" id="id">style</css>
+ <html>additional html</html>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </calendar>
+
+ <checkbox name="checkbox" elname="checkbox" frozen="false" checked="false">
+ value
+ <css class="css class" id="id">style</css>
+ <html accesskey="A" tabindex="1">additional html</html>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </checkbox>
+
+ <combo name="combo" elname="combo" inputsize="1" readonly="false" sort="true"
+frozen="false" add="true" size="1">
+ 1
+ <options>
+ <option value="1">1</option>
+ <option value="2">2</option>
+ </options>
+ <intros errormsg = "Don't select me">
+ <intro value="0">intro</intro>
+ </intros>
+ <validation>
+ <length min="1" max="2">length_e</length>
+ <regexp reg="" icase="false">valid_e</regexp>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ <css class="css class" id="id">style</css>
+ <html accesskey="O" tabindex="2">additional html</html>
+ </combo>
+
+ <date name="date" elname="date" language="en" frozen="false" preload="false"
+format="d.m.Y" now="jetzt" intro="" intro_e="">
+ value
+ <limits>
+ <yearlong min="1990" max="2010"/>
+ <yearshort min="90" max="99"/>
+ </limits>
+ <html>additional html</html>
+ <css class="css class" id="id">style</css>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </date>
+
+ <file size="1" accept="" name="file" elname="file" frozen="false">
+ value
+ <html accesskey="" tabindex="">additional html</html>
+ <css class="css class" id="id">style</css>
+ <validation>
+ <length min="0" max="1">length_e</length>
+ <regexp reg="" icase="false">valid_e</regexp>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </file>
+
+ <fileupload size="1" maxfilesize="100" accept="" name="fileupload"
+elname="fileupload" frozen="false">
+ value
+ <html accesskey="" tabindex="">additional html</html>
+ <css class="css class" id="id">style</css>
+ <validation>
+ <length min="0" max="1">length_e</length>
+ <regexp reg="" icase="false">valid_e</regexp>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </fileupload>
+
+ <hidden name="hidden" elname="hidden" frozen="false">
+ value
+ <html>additional html</html>
+ <css class="css class" id="id">style</css>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </hidden>
+
+ <image name="image" elname="image" align="" alt="" hspace="1" vspace="1"
+border="1" width="1" height="1" usemap="" frozen="false">
+ src
+ <html accesskey="" tabindex="">additional html</html>
+ <css class="css class" id="id">style</css>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </image>
+
+ <password name="password" elname="password" size="-1" readonly="false"
+frozen="false">
+ value
+ <css class="css class" id="id">style</css>
+ <html accesskey="" tabindex="">additional html</html>
+ <validation>
+ <length min="0" max="-1">length_e</length>
+ <regexp reg="" icase="false">valid_e</regexp>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </password>
+
+ <radio name="radio" elname="radio" checked="false" frozen="false">
+ value
+ <css class="css class" id="id">style</css>
+ <html accesskey="" tabindex="">additional html</html>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </radio>
+
+ <reset name="reset" elname="reset" frozen="false" width="1" height="1">
+ <css class="css class" id="id">style</css>
+ <html accesskey="" tabindex="">additional html</html>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </reset>
+
+ <select name="select" elname="select" frozen="false" size="0" multiple="false">
+ value
+ <options>
+ <option value=""/>
+ </options>
+ <intros errormsg="error">
+ <intro value="">intro</intro>
+ </intros>
+ <html accesskey="" tabindex="">additional html</html>
+ <css class="css class" id="id">style</css>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </select>
+
+ <submit name="submit" elname="submit" width="1" height="1" frozen="false"
+accesskey="" tabindex="">
+ value
+ <html accesskey="" tabindex="">additional html</html>
+ <css class="css class" id="id">style</css>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </submit>
+
+ <text name="text" elname="text" size="-1" readonly="false" frozen="false">
+ value
+ <css class="css class" id="id">style</css>
+ <html accesskey="" tabindex="">additional html</html>
+ <validation>
+ <length min="0" max="-1">length_e</length>
+ <regexp reg="" icase="false">valid_e</regexp>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </text>
+
+ <textarea name="textarea" elname="textarea" rows="1" cols="1" wrap="virtual"
+readonly="false" frozen="false">
+ value
+ <css class="css class" id="id">style</css>
+ <html accesskey="" tabindex="">additional html</html>
+ <validation>
+ <length min="0" max="-1">length_e</length>
+ <regexp reg="" icase="false" global="false">valid_e</regexp>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </textarea>
+
+ <textedit name="textedit" elname="textedit" frozen="false">
+ value
+ <css class="css class" id="id">style</css>
+ <html accesskey="" tabindex="">additional html</html>
+ <validation>
+ <phpfunction></phpfunction>
+ <jsfunction></jsfunction>
+ </validation>
+ </textedit>
+ </elements>
</form>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]