Can be bug in a class oohforms (PHPLid 7.2d, 7.4-pre):
When I add regex in the form's element definition and
element type is text and this element is the first in
form, the method self_get_js() gives out erroneous JS-
code for the first element - it addresses to him
elements[] instead of elements[0].
Here is some JS-code generated by phpLib validation:
--- cut ---
<script language='javascript'>
<!--
function paym_report_Validator(f) {
if (window.RegExp) {
var reg = new RegExp("^[0-9]+$","g");
if (!reg.test(f.elements[].value)) {
alert("Numeric only");
f.elements[].focus();
return(false);
}
}
if (window.RegExp) {
var reg = new RegExp("^[0-9][0-9]\.[0-9][0-9]\.[0-9]
[0-9][0-9][0-9]$|^$","g");
if (!reg.test(f.elements[1].value)) {
alert("Date format : DD.MM.YYYY");
f.elements[1].focus();
return(false);
}
}
}
//-->
</script>
--- cut ---
Logged In: YES
user_id=383633
When i was adding this bug, i couldn't add a file
attachment. Here it is in plain text:
<-- cut valtest.php -->
<?php
$t = new Template();
$f = new form;
$FORM = array(
"F_FIELD1" => array(
"type" => "text",
"name" => "field1",
"size" => "40",
"value" => "",
"valid_regex" => "^[0-9]*$",
"valid_e" => "Numeric only"),
"F_FIELD2" => array(
"type" => "text",
"name" => "field2",
"size" => "10",
"maxlength" => "10",
"value" => "",
"valid_regex"
=> "^\d\d\.\d\d\.\d\d\d\d$|^$",
"valid_e" => "Date format : DD.MM.YYYY"),
"F_SUBMIT" => array(
"type" => "submit",
"name" => "check",
"value" => "Check")
);
$t->set_file("page", "valtest.thtml");
foreach ($FORM as $k => $v) {
$f->add_element($v);
$t->set_var($k, $f->get_element($v['name']));
}
$t->set_var(array(
"F_START" => $f->get_start("valtest", "post",
$PHP_SELF),
"F_END" => $f->get_finish())
);
$t->pparse("OUT", "page");
?>
<-- cut valtest.php -->
<-- cut valtest.thtml -->
<html>
<head>
<title>Some PHPLib JS-validation testing</title>
</head>
<body>
Try to fill in form with invalid values and click "Check"
button to validate data<p>
{F_START}
Some numeric : {F_FIELD1}<br>
Some date in DD.MM.YYYY style : {F_FIELD2}<p>
{F_SUBMIT}
{F_END}
</body>
</html>
<-- cut valtest.thtml -->
Logged In: YES
user_id=166685
I ran into the same problem, and made a workaround.
The real cause is not solved but it works anyway :).
A) Edit of_text.inc
B) goto line 64 where the following function starts:
64: function self_get_js($ndx_array) {
65: $str = "";
66:
67: reset($ndx_array);
68: while (list($k,$n) = each($ndx_array)) {
69:
C) Add this:
70: if( !isset( $n ) ) $n=0; ## ER 20020311: BUGFIX
This fix should take care of it.
Logged In: YES
user_id=166685
I ran into the same problem, and made a workaround.
The real cause is not solved but it works anyway :).
A) Edit of_text.inc
B) goto line 64 where the following function starts:
64: function self_get_js($ndx_array) {
65: $str = "";
66:
67: reset($ndx_array);
68: while (list($k,$n) = each($ndx_array)) {
69:
C) Add this:
70: if( !isset( $n ) ) $n=0; ## ER 20020311: BUGFIX
This fix should take care of it.