Date: 11/17/99
- Next message: ssilk: "[PHPLIB-DEV] cvs commit"
- Previous message: Giancarlo: "[PHPLIB-DEV] phplib-xmlrpc extension"
- Next in thread: Massimiliano Masserelli: "Re: [PHPLIB-DEV] cvs commit"
- Reply: Massimiliano Masserelli: "Re: [PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: uw
Date: Thu Nov 18 00:47:43 1999
Modified files:
php-lib/php/of_file.inc
php-lib/php/of_radio.inc
php-lib/php/of_select.inc
php-lib/php/of_text.inc
php-lib/php/of_textarea.inc
php-lib/php/oohforms.inc
Log message:
Added a functions to generate php-code for form result validation
Index: php-lib/php/of_file.inc
diff -u php-lib/php/of_file.inc:1.3 php-lib/php/of_file.inc:1.4
--- php-lib/php/of_file.inc:1.3 Thu Oct 14 17:37:41 1999
+++ php-lib/php/of_file.inc Thu Nov 18 00:47:41 1999
@@ -3,7 +3,7 @@
*
* Copyright (c) 1998 by Jay Bloodworth
*
- * $Id: of_file.inc,v 1.3 1999/10/14 15:37:41 negro Exp $
+ * $Id: of_file.inc,v 1.4 1999/11/17 23:47:41 uw Exp $
*/
class of_file extends of_element {
@@ -22,7 +22,7 @@
$str .= "<input type='file' name='$this->name'";
if ($this->extrahtml)
$str .= " $this->extrahtml";
- $str .= ">";
+ $str .= ">\n";
$count = 2;
return $str;
Index: php-lib/php/of_radio.inc
diff -u php-lib/php/of_radio.inc:1.4 php-lib/php/of_radio.inc:1.5
--- php-lib/php/of_radio.inc:1.4 Thu Oct 14 17:37:41 1999
+++ php-lib/php/of_radio.inc Thu Nov 18 00:47:42 1999
@@ -3,7 +3,7 @@
*
* Copyright (c) 1998 by Jay Bloodworth
*
- * $Id: of_radio.inc,v 1.4 1999/10/14 15:37:41 negro Exp $
+ * $Id: of_radio.inc,v 1.5 1999/11/17 23:47:42 uw Exp $
*/
class of_radio extends of_element {
@@ -23,7 +23,7 @@
$str .= " $this->extrahtml";
if ($this->value==$val)
$str .= " checked";
- $str .= ">";
+ $str .= ">\n";
$count = 1;
return $str;
Index: php-lib/php/of_select.inc
diff -u php-lib/php/of_select.inc:1.4 php-lib/php/of_select.inc:1.5
--- php-lib/php/of_select.inc:1.4 Thu Oct 14 17:37:41 1999
+++ php-lib/php/of_select.inc Thu Nov 18 00:47:42 1999
@@ -3,7 +3,7 @@
*
* Copyright (c) 1998 by Jay Bloodworth
*
- * $Id: of_select.inc,v 1.4 1999/10/14 15:37:41 negro Exp $
+ * $Id: of_select.inc,v 1.5 1999/11/17 23:47:42 uw Exp $
*/
class of_select extends of_element {
@@ -33,7 +33,7 @@
$str .= " size='$this->size'";
if ($this->extrahtml)
$str .= " $this->extrahtml";
- $str .= ">";
+ $str .= ">\n";
reset($this->options);
while (list($k,$o) = each($this->options)) {
@@ -52,7 +52,7 @@
}
$str .= ">" . (is_array($o) ? $o["label"] : $o) . "\n";
}
- $str .= "</select>";
+ $str .= "</select>\n";
$count = 1;
return $str;
Index: php-lib/php/of_text.inc
diff -u php-lib/php/of_text.inc:1.6 php-lib/php/of_text.inc:1.7
--- php-lib/php/of_text.inc:1.6 Thu Oct 14 17:37:41 1999
+++ php-lib/php/of_text.inc Thu Nov 18 00:47:42 1999
@@ -3,7 +3,7 @@
*
* Copyright (c) 1998 by Jay Bloodworth
*
- * $Id: of_text.inc,v 1.6 1999/10/14 15:37:41 negro Exp $
+ * $Id: of_text.inc,v 1.7 1999/11/17 23:47:42 uw Exp $
*/
class of_text extends of_element {
@@ -40,7 +40,7 @@
$str .= " size='$this->size'";
if ($this->extrahtml)
$str .= " $this->extrahtml";
- $str .= ">";
+ $str .= ">\n";
$count = 1;
return $str;
@@ -101,7 +101,36 @@
}
return false;
}
+
+ function self_validate_php($val) {
+
+ $php_code = "";
+ if (!is_array($val)) $val = array($val);
+ reset($val);
+ while (list($k, $v)=each($val)) {
+
+ if ($this->length_e) {
+ $condition = "";
+ if ($this->minlength) $condition.=sprintf("(strlen($%s)<%s) || ", $this->name, (int)$this->minlength);
+ if ($this->maxlength) $condition.=sprintf("(strlen($%s)>%s) || ", $this->name, (int)$this->maxlength);
+ if (""!=$condition) {
+ $condition.="false";
+ $php_code.= $this->generate_php($condition, $this->name, $this->title, $this->length_e);
+ }
+ }
+
+ if ($this->valid_e) {
+ $condition = "";
+ if ($this->icase)
+ $condition.= sprintf("(!eregi(\"%s\", \"$%s\"))", $this->valid_regex, $this->name);
+ else
+ $condition.= sprintf("(!ereg(\"%s\", \"$%s\"))", $this->valid_regex, $this->name);
+ if (""!=$condition)
+ $php_code.=$this->generate_php($condition, $this->name, $this->title, $this->valid_e);
+ }
+ }
+ return $php_code;
+ } // end func self_validate_php($val)
} // end TEXT
-
-?>
+?>
\ No newline at end of file
Index: php-lib/php/of_textarea.inc
diff -u php-lib/php/of_textarea.inc:1.6 php-lib/php/of_textarea.inc:1.7
--- php-lib/php/of_textarea.inc:1.6 Thu Oct 14 17:37:41 1999
+++ php-lib/php/of_textarea.inc Thu Nov 18 00:47:42 1999
@@ -3,7 +3,7 @@
*
* Copyright (c) 1998 by Jay Bloodworth
*
- * $Id: of_textarea.inc,v 1.6 1999/10/14 15:37:41 negro Exp $
+ * $Id: of_textarea.inc,v 1.7 1999/11/17 23:47:42 uw Exp $
*/
class of_textarea extends of_element {
@@ -25,7 +25,7 @@
$str .= " wrap='$this->wrap'";
if ($this->extrahtml)
$str .= " $this->extrahtml";
- $str .= ">" . htmlspecialchars($this->value) ."</textarea>";
+ $str .= ">" . htmlspecialchars($this->value) ."</textarea>\n";
$count = 1;
return $str;
@@ -42,6 +42,25 @@
$count = 1;
return $str;
}
+
+ function self_validate_php($val) {
+
+ $php_code = "";
+
+ if ($this->length_e) {
+ if ($this->minlength) {
+ $condition.=sprintf("(strlen($%s) < %s) ||", $this->name, (int)$this->minlength);
+ } else if ($this->maxlength) {
+ $condition.=sprintf("(strlen($%s) > %s) ||", $this->name, (int)$this->maxlength);
+ }
+ if (""!=$condition) {
+ $condition.="false";
+ $php_code.= $this->generate_php($condition, $this->name, $this->title, $this->length_e);
+ }
+ }
+
+ return $php_code;
+ } // end func self_validate_php
} // end TEXTAREA
Index: php-lib/php/oohforms.inc
diff -u php-lib/php/oohforms.inc:1.18 php-lib/php/oohforms.inc:1.19
--- php-lib/php/oohforms.inc:1.18 Tue Oct 26 14:51:38 1999
+++ php-lib/php/oohforms.inc Thu Nov 18 00:47:42 1999
@@ -5,7 +5,7 @@
*
* Copyright (c) 1998 by Jay Bloodworth
*
- * $Id: oohforms.inc,v 1.18 1999/10/26 12:51:38 negro Exp $
+ * $Id: oohforms.inc,v 1.19 1999/11/17 23:47:42 uw Exp $
*/
class of_element {
@@ -43,6 +43,10 @@
function self_validate($val) {
return false;
}
+
+ function self_validate_php($val) {
+ return false;
+ }
function self_get_js($ndx_array) {
}
@@ -73,6 +77,10 @@
$this->$k = $v;
}
}
+
+ function generate_php ($condition, $name, $title, $error) {
+ return sprintf("if (%s) {\n\t$%s.=\"%s\\n\";\n\t$%s[\"%s\"] = array ( \"%s\", \"%s\");\n};\n", $condition, "error_msg", $error, "error_flag", $name, $title, $error);
+ }
} // end ELEMENT
@@ -241,7 +249,7 @@
// harm in $this->elements
# Original match
# if (preg_match("/(\w+)\[(d+)\]/i", $el[name], $regs)) {
- if (ereg("([a-zA-Z_]+)\\[([0-9]+)\\]", $el["name"], $regs)) {
+ if (ereg("([a-zA-Z_]+)\[([0-9]+)\]", $el["name"], $regs)) {
$el["name"] = sprintf("%s{%s}", $regs[1], $regs[2]);
$el["multiple"] = true;
}
@@ -262,7 +270,7 @@
// see add_element: translate $foo[int] to $foo{int}
# Original pattern
# if (preg_match("/(w+)\[(\d+)\]/i", $name, $regs) {
- if (ereg("([a-zA-Z_]+)\\[([0-9]+)\\]", $name, $regs)) {
+ if (ereg("([a-zA-Z_]+)\[([0-9]+)\]", $name, $regs)) {
$org_name = $name;
$name = sprintf("%s{%s}", $regs[1], $regs[2]);
$flag_nametranslation = true;
@@ -329,6 +337,32 @@
}
return $default;
}
+
+ function php_validate($vallist="") {
+
+ if ($vallist) {
+ if (!is_array($vallist)) $vallist = array($vallist);
+ reset($vallist);
+ $elrec = $this->elements[current($vallist)];
+ } else {
+ reset($this->elements);
+ $elrec = current($this->elements);
+ }
+
+ $php_code = "";
+ while ($elrec) {
+ $el = $elrec["ob"];
+ $php_code.=$el->self_validate_php($el->value);
+ if ($vallist) {
+ next($vallist);
+ $elrec = $this->elements[current($vallist)];
+ } else {
+ next($this->elements);
+ $elrec = current($this->elements);
+ }
+ }
+ return $php_code;
+ }
function load_defaults($deflist="") {
if ($deflist) {
-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.
- Next message: ssilk: "[PHPLIB-DEV] cvs commit"
- Previous message: Giancarlo: "[PHPLIB-DEV] phplib-xmlrpc extension"
- Next in thread: Massimiliano Masserelli: "Re: [PHPLIB-DEV] cvs commit"
- Reply: Massimiliano Masserelli: "Re: [PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

