Re: QuickForm & validation with new renderer

From: Date: Fri, 29 Dec 2006 00:27:12 +0000
Subject: Re: QuickForm & validation with new renderer
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-26225@lists.php.net to get a copy of this message
On Thu, Dec 28, 2006 at 12:26:13AM -0500, Brian Clark wrote: > Hi, I'm replying to myself for the sake of the archives. > 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); I removed those two lines above, and... > if ($qf->validate()) { > $qf->freeze(); > $qf->process('processForm', false); > } else { > //$qf->display(); > print $renderer->toHtml(); > } It works as expected when I change the above bit to the following: if ($qf->validate()) { $qf->freeze(); $qf->process('processForm', false); } else { $renderer = &new HTML_QuickForm_Renderer_CustomerForm(); $qf->accept($renderer); print $renderer->toHtml(); } I'm not entirely sure why that works. I'm guessing it does because validate() updates the HTML with the red text markers for the required fields? -- Brian Clark

« previous php.pear.general (#26225) next »