[Patch] HTML_QuickFrom_Renderer_Defaut generates proper HTML

From: Date: Mon, 15 Aug 2005 15:45:49 +0000
Subject: [Patch] HTML_QuickFrom_Renderer_Defaut generates proper HTML
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-39365@lists.php.net to get a copy of this message
Hello Adam and Bertrand, I am a happy user of QuickForm but I noticed the Default renderer does not generate proper HTML (According to HTML_Tidy). It outputs a HTML fragment but not a full page. At present the JavaScript is just put in front of the form tag, and the user has no control over its placement. Here is a patch that changes the default form template and puts the JavaScript inside the head of the form. It introduces a new placeholder "{validation}" that sets the place for the validation script. I am not completely sure if this is the right way to solve this problem, as now you cannot insert a form into an existing page. But then again, the JavaScript should end up in the header and not the body of any page. You could also add a new attribute of the form that requests a complete HTML page or a HTML fragment. This attribute could then choose between the two form templates. One for a fragment, and one for a complete page. In any case the solution should use a placeholder (Like {validation} ) so a user that wants to override the default template has control over where the javascript ends up. A user could also install a template without the {validation} placeholder, and extract the JavaScript himself for placement wherever he likes. Hope this is useful, Kind Regards, Reinier Kleipool The Netherlands

Index: QuickForm/Renderer/Default.php =================================================================== RCS file: /repository/pear/HTML_QuickForm/QuickForm/Renderer/Default.php,v retrieving revision 1.14 diff -u -r1.14 Default.php --- QuickForm/Renderer/Default.php 24 Jun 2005 17:57:16 -0000 1.14 +++ QuickForm/Renderer/Default.php 15 Aug 2005 15:26:05 -0000 @@ -58,8 +58,24 @@ * @var string * @access private */ - var $_formTemplate = - "\n<form{attributes}>\n<div>\n{hidden}<table border=\"0\">\n{content}\n</table>\n</div>\n</form>"; + var $_formTemplate = <<<END +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html lang="en"> + <head> + {validation} + </head> + <body> + <form{attributes}> + <div> + {hidden} + <table border="0"> + {content} + </table> + </div> + </form> + </body> +</html> +END; /** * Required Note template string @@ -194,11 +210,13 @@ $this->_html .= $this->_hiddenHtml; } $this->_hiddenHtml = ''; - $this->_html = str_replace('{content}', $this->_html, $html); // add a validation script - if ('' != ($script = $form->getValidationScript())) { - $this->_html = $script . "\n" . $this->_html; - } + if ('' != ($script = $form->getValidationScript())) + $html= str_replace('{validation}', $form->getValidationScript(), $html); + else + $html = str_replace('{validation}', '', $html); + + $this->_html = str_replace('{content}', $this->_html, $html); } // end func finishForm /**
« previous php.pear.dev (#39365) next »