HTML_QuickForm2
[ class tree: HTML_QuickForm2 ] [ index: HTML_QuickForm2 ] [ all elements ]

Source for file default-renderer.php

Documentation is available at default-renderer.php

  1. <?php
  2. /**
  3.  * Usage example for HTML_QuickForm2 package: default renderer
  4.  *
  5.  * The example demonstrates how the default renderer can be used and abused.
  6.  * It also provides a default stylesheet.
  7.  *
  8.  * $Id: default-renderer.php 288534 2009-09-21 15:21:42Z avb $
  9.  */
  10. ?>
  11. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  12.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  13. <html>
  14.   <head>
  15.     <style type="text/css">
  16.       body { margin: 0; padding: 0; font: 80%/1.5 Arial,Helvetica,sans-serif; color: #111; background-color: #FFF; }
  17.       .quickform { margin: 5px; padding: 5px; background-color: #FFF; }
  18.       .quickform form fieldset { margin: 10px 0; padding: 10px; border: #DDD 1px solid; }
  19.       .quickform form legend { font-weight: bold; color: #666; }
  20.       .quickform form div.element { padding: 0.25em 0; }
  21.       .quickform form label,
  22.       .quickform span.qf-label { margin-right: 10px; padding-right: 10px; width: 150px; display: block; float: left; text-align: right; position: relative; }
  23.       .quickform form .required:after { position: absolute; right: 0; font-size: 120%; font-style: normal; color: #C00; content: "*"; }
  24.       .quickform form .qf-label-1 { margin-left:160px; padding-left:10px; color:#888; font-size: 85%; }
  25.       .quickform div.reqnote { font-size: 92%; color: #555; }
  26.       .quickform div.reqnote em { font-style: normal; color: #C00; }
  27.       .quickform div.reqnote strong { color:#000; font-weight: bold; }
  28.       .quickform div.errors { background-color: #FEE; border: 1px solid #ECC; padding:5px; margin:0 0 20px 0 }
  29.       .quickform div.errors p,
  30.       .quickform div.errors ul { margin:0; }
  31.       .quickform div.error input { border-color: #C00; background-color: #FEF; }
  32.       .quickform div.qf-checkable label, 
  33.       .quickform div.qf-checkable input { display: inline; float: none; }
  34.       .quickform div.qf-checkable div,
  35.       .quickform div.qf-message { margin-left: 170px; }
  36.       .quickform div.qf-message { font-size: 88%; color: #C00; }
  37.     </style>
  38.     <title>HTML_QuickForm2 default renderer example</title>
  39.   </head>
  40.   <body>
  41. <?php
  42.  
  43. require_once 'HTML/QuickForm2.php';
  44. require_once 'HTML/QuickForm2/Renderer.php';
  45.  
  46. $form = new HTML_QuickForm2('example');
  47. $fs $form->addFieldset()->setLabel('Your information');
  48.  
  49. $username $fs->addText('username')->setLabel('Username');
  50. $username->addRule('required''Username is required');
  51.  
  52. $password $fs->addPassword('pass')
  53.             ->setLabel(array('Password''Password should be 8 characters at minimum'));
  54. $password->addRule('required''Password is required');
  55.  
  56. $form->addHidden('my_hidden1')->setValue('1');
  57. $form->addHidden('my_hidden2')->setValue('2');
  58. $form->addSubmit('submit'array('value' => 'Send''id' => 'submit'));
  59.  
  60. if ($form->validate()) {
  61.     $form->toggleFrozen(true);
  62. }
  63.  
  64.  
  65. $renderer HTML_QuickForm2_Renderer::factory('default')
  66.     ->setOption(array(
  67.         'group_hiddens' => true,
  68.         'group_errors'  => true,
  69.         'required_note' => '<strong>Note:</strong> Required fields are marked with an asterisk (<em>*</em>).'
  70.     ))
  71.     ->setTemplateForId('submit''<div class="element">{element} or <a href="/">Cancel</a></div>')
  72.     ->setTemplateForClass(
  73.         'HTML_QuickForm2_Element_Input',
  74.         '<div class="element<qf:error> error</qf:error>"><qf:error>{error}</qf:error>' .
  75.         '<label for="{id}" class="qf-label<qf:required> required</qf:required>">{label}</label>' .
  76.         '{element}' .
  77.         '<qf:label_2><div class="qf-label-1">{label_2}</div></qf:label_2></div>' 
  78.     );
  79.  
  80. echo $form->render($renderer);
  81. ?>
  82. </body>
  83. </html>

Documentation generated on Mon, 11 Mar 2019 15:34:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.