[prev in list] [next in list] [prev in thread] [next in thread] 

List:       phplib-dev
Subject:    [PHPLIB-DEV] Possible Bug OOHFORMS
From:       Bob Strouper <bobw123 () mail ! com>
Date:       1999-11-27 19:54:04
[Download RAW message or body]

Hello,

It looks like there is a bug in oohforms regarding of_text.inc
and the creation of its javascript code.

This is the bug:
When I assign a javascript name to start("javascriptname") and
add two form elements to the page ( one is a TEXT, and one is SELECT )
and display ONLY the SELECT, for some reason oohforms tries to create
the javascript code for the TEXT element.  It calls function
self_get_js($ndx_array) in of_text and asigns a bogus value to
its argument, thus erroring with a:
Warning: Variable passed to reset() is not an array or object in of_text.inc
on line 67
Warning: Variable passed to each() is not an array or object in of_text.inc
on line 68

Here is some code that reproduces the problem ( the following code
has no real logic other than to reproduce the error ):

<?require("oohforms.inc");
$f = new form;

$o = array(array("label"=>"Select one","value"=>0),
array("label"=>"one","value"=>1),
array("label"=>"two","value"=>2));

$f->add_element(array("type"=>"select",
"name"=>"dropdown",
"options"=>$o,
"valid_e"=>"please select one",
"size"=>1));

$f->add_element(array("type"=>"text",
"name"=>"mytext",
"valid_regex"=>"^[a-zA-Z1-9_ -]+$",
"valid_e"=>"Text box is not valid"));

$f->add_element(array("type"=>"submit",
"name"=>"mysubmit"));

$f->start("javascriptname");

echo "Dispaying form without the text element<br>\n\n";
$f->show_element("dropdown");
echo "<br>\n";
$f->show_element("mysubmit","upload");

$f->finish();?>

Why do I want to create a form element and not show it you may ask?
Well, it all comes down to how I redisplay the form upon validation
error ( a form that includes input type FILE )

I figure I have three choices:
1) Display the complete form again, loading the defaults for the elements
that have passed the validation
2) Display the complete form again, FREEZING the defaults for the elements
that have passed the validation
3) Display ONLY the form elements that did NOT pass the validation
and registering the good ones.

Now, since I am working with input type FILE, the third choice
seems to be the only choice, since upon redisplay of the form,
all file type fields are lost between validate and redisplay.

So here is what I do.

Upon form submission I validate a predefined list of form elements,
( the ones that I know are coming to this page ) while checking them
against the HTTP_POST_VARS. ( NOTE: as oohforms currently
stands, validate only takes an array as an argument, so I have to
convert each individual form element into a temporary array):

!$sess->is_registered("good_el_array")? $sess->register("good_el_array"):0;
$validate_array =
array("element_one","element_two","element_three","element_four","element_five");
reset($validate_array);
while (list($key, $val) = each($validate_array) )
$temparray[]=$val;
if (isset($HTTP_POST_VARS[$val]) )
{
$error = $f->validate("ok",$temparray);
if ($error == "ok")
{
if (!isset($good_el_array[$val]))
$good_el_array[$val] = ${$val};
}
else
if (!isset($bad_el_array[$val]))
$bad_el_array[] = $val;
}
unset($temparray);
}

Now I have two arrays, $good_el_array ( which is registered ) and
$bad_el_array.  What I do now is repaint the form by passing only
the "array elements" from $bad_el_array to show_element ( in a loop ),
but when I do this I get the error as I described before.

One solution ( a workaround ) that might work is to delete the
form element after my validation ( unset($myformobject) ) and then
build a completly new form from the $bad_el_array. But I hesitate to
delete the form.

I look forward to hearing from you.

Thanks in advance

Bob

__________________________________________________
FREE Email for ALL! Sign up at http://www.mail.com

-
PHPLIB Developers Mailing List. Send messages to <phplib-dev@lists.netuse.de>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request@lists.netuse.de> in
the body, not the subject, of your message.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic