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

List:       pear-general
Subject:    Re: [PEAR] QuickForm & validation with new renderer
From:       Brian Clark <brianj+nevdull () unwell ! org>
Date:       2006-12-29 0:27:12
Message-ID: 20061229002712.GA10175 () machismo
[Download RAW message or body]

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

-- 
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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

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