QuickForm & validation with new renderer
| From: | Brian Clark | Date: | Thu, 28 Dec 2006 05:26:13 +0000 |
| Subject: | QuickForm & validation with new renderer | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-26215@lists.php.net to get a copy of this message | ||
Hi,
I'm using HTML_QuickForm 3.2.7.
When I copy the Default.php renderer, rename it to CustomerForm.php and
change the name of the class to HTML_QuickForm_Renderer_CustomerForm, if
I disable JavaScript in Firefox, I no longer get the red warning
messages above the text fields when I submit the form. The client
validation, when JavaScript is enabled, sends the alert() just fine
however.
The only thing changed in HTML_QuickForm_Renderer_CustomerForm was:
var $_ =
"\n\t<tr>\n\t\t<td class=\"heading\" align=\"right\"
valign=\"top\" colspan=\"2\">{header}</td>\n\t</tr>";
A sample which should reproduce my problem:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Customer Form</title>
<style type="text/css">
* {
font-family: "MS Trebuchet", sans-serif;
}
.heading {
background-color: #006fc4;
color: #FFFFFF;
font-weight: bold;
padding: 5px;
}
</style>
</head>
<body>
<?php
require_once('HTML/QuickForm.php');
require_once('CustomerForm.php');
$qf = new HTML_QuickForm('newcustomer','post');
$qf->addElement('header','personalheader','Personal Information');
$qf->addElement('text','first','What is your first name:');
$qf->addRule('first','First name is
required','required',null,'client');
$qf->applyFilter('__ALL__','trim');
$qf->addElement('submit', 'submit', 'Create Customer Record');
$renderer = &new HTML_QuickForm_Renderer_CustomerForm();
$qf->accept($renderer);
if ($qf->validate()) {
$qf->freeze();
$qf->process('processForm', false);
} else {
//$qf->display();
print $renderer->toHtml();
}
function processForm($values) {
print '<pre>';
print_r($values);
print '</pre>';
}
?>
Thanks for any hints!
--
Brian Clark