Date: 11/21/99
- Next message: Ronny Hanssen: "[PHPLIB] About gc() in session.inc"
- Previous message: Kristian Koehntopp: "Re: [PHPLIB] Using Setup.inc"
- In reply to: Bob Strouper: "[PHPLIB] Kristian: A couple questions please"
- Next in thread: sam1600 <email protected>: "Re:[PHPLIB] Changes to oohform, was: Kristian: A couple questions please"
- Maybe reply: sam1600 <email protected>: "Re:[PHPLIB] Changes to oohform, was: Kristian: A couple questions please"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Bob Strouper wrote:
>
> Hello,
>
> Would you please post to the list a short description of
> how to use the new functions "generate_php()" and/or
> "php_validate()".
Bob,
I made these changes, let me explain them. Excuse me, the new functions
are'nt ducumented yet.
When I was thinking of how to ease html form generation, I started to
work with oohform. I was pleased to see no html and javascript in my
code, but I was disappointed of how much work was still mine: placing
the form element in a template, writing php code for form validation. I
was dreaming of one template for all and automatically generated php
validation code.
A look at my forms showed that they have one common, 3 cell table
layout:
Description - Image showing the status (error, ok) - formelement
The image describes the status of the formelement. It shows eigther a
red questionary (wrong or missing value, alt attribute contains help
message) or a green questionary (none value necessary or correct value,
alt attribute contains help message). I wrote a "one for all" template
and kind of a wrapper beetween oohform and FastTemplate. The wrapper
class has an method add_element() similar to the oohform add_element()
with one additional flag for the image. At this stage all the forms in
my application looked the same. All I had to do to get a html form was
calling add_element(). Half of the work was done.
The javascript code generation of oohform is beautiful, but I does not
save me writing (individiual) php code for form result validation.
Looking again at my forms showed that most of my formelements are text
or textarea fields. Oohform could easily generate some php code for me.
I placed in of_text, of_textarea new functions that look similar to
self_validate():
function self_validate_php($val) {
$php_code = "";
[...]
if ($this->length_e) {
$condition = "";
if ($this->minlength) $condition.=sprintf("(strlen($%s)<%s) || ",
$this->name, (int)$this->minlength);
[...]
if (""!=$condition) {
$condition.="false";
$php_code.= $this->generate_php($condition, $this->name,
$this->title, $this->length_e);
}
}
} // end func self_validate_php
$condition contains php code, $this->generate_php() expands it to an
if-construct like:
if ((strlen($name) < 1) ||false) {
$error_msg.="Please enter your name!\n";
$error_flag["name"] = array ( "Name", "Please enter you name");
};
php_validate() gives you all the generated php code. This code can be
registered as a session variable and be executed when the form has been
sent.
$php_code = $ooh->php_validate();
$sess->register(base64_decode($php_code));
if ($submit)
if (""==$php_code)
eval(base64_decode($php_code));
}
Now you'll have two new variables:
- $error_msg
- $error_flag
$error_msg contains all error messages (like the javascript code:
valid_e, length_e...). $error_flag is an array:
$error_flag["name"]=array("title", "error message: valid_e,
length_e...");
The variables follow a strucure I choosed in the oohform to template
wrapper. The wrapper was duringwhile rewritten to use phplib/Template
instead of FastTemplate. I'm waiting for Kristian to comment on it and
the possibility of placing it in the phplib.
Again, excuse me I'll soon write a documentation.
Ulf
-
PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
the body, not the subject, of your message.
- Next message: Ronny Hanssen: "[PHPLIB] About gc() in session.inc"
- Previous message: Kristian Koehntopp: "Re: [PHPLIB] Using Setup.inc"
- In reply to: Bob Strouper: "[PHPLIB] Kristian: A couple questions please"
- Next in thread: sam1600 <email protected>: "Re:[PHPLIB] Changes to oohform, was: Kristian: A couple questions please"
- Maybe reply: sam1600 <email protected>: "Re:[PHPLIB] Changes to oohform, was: Kristian: A couple questions please"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

