Skip to content

Instantly share code, notes, and snippets.

@shupp
Created January 18, 2010 19:01
Show Gist options
  • Save shupp/280264 to your computer and use it in GitHub Desktop.
Save shupp/280264 to your computer and use it in GitHub Desktop.
diff --git a/public_html/index.php b/public_html/index.php
index 2d6a659..9fba63c 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -3,9 +3,26 @@
require_once '../RandomString.php';
require_once 'HTML/QuickForm.php';
+
+
// Instantiate the HTML_QuickForm object
$form = new HTML_QuickForm('random');
+/// Illustration of customizing required notes for n00b973
+require_once 'HTML/QuickForm/Renderer/Default.php';
+class MyCustomRenderer extends HTML_QuickForm_Renderer_Default
+{
+ var $_elementTemplate =
+ "\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\"><!-- BEGIN required --><span style=\"color: #ffff00\">@</span><!-- END required --><b>{label}</b></td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>"
+}
+
+// Update required note on form object
+$form->setRequiredNote('<span style="font-size:80%; color:#ffff00;">@</span><span style="font-size:80%;"> denotes required field</span>');
+
+// Add renderer
+$renderer = new MyCustomRenderer();
+// End custom renderer creation, but don't accept it until the end of the form
+
// Set defaults for the form elements
$form->setDefaults(array(
'lines' => 1,
@@ -32,7 +49,10 @@ $form->addRule('lines', 'Number of strings required', 'required', '', 'client');
// Output
echo "<html><body><center>\n";
-$form->display();
+
+// Accept renderer and display
+$form->accept($renderer);
+echo $renderer->toHtml();
// Try to validate, and generate strings if valid
if ($form->validate()) {
shupp@shupp:~/www/random.shupp.org$ git br
* master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment