[cvs] [Wiki] changed: Doc/Dev/FormPackage

Wiki Guest wikiguest at horde.org
Sun Apr 16 20:28:22 PDT 2006


guest [207.172.212.178]  Sun, 16 Apr 2006 20:28:22 -0700

Modified page: http://wiki.horde.org/Doc/Dev/FormPackage
New Revision:  1.8
Change log:  first pass at updating these for the current coding standards and horde_form code

@@ -3,9 +3,9 @@
 [[toc]]
 
 ++ What form input types are there?
 
-There are many different [((Doc/Dev/FormTypes)) form input types]. To many to list here, follow [((Doc/Dev/FormTypes)) this link].
+See ((Doc/Dev/FormTypes)).
 
 ++ Filling a form with values
 
 The following code could be used to fill a form through Horde_Form, for example to edit a record. The example is a bit abstracted from reality, in that you would also need to build some validation around this code, checking for a form submission, etc. to eventually have a useable form.
@@ -13,21 +13,22 @@
 <code type="php">
 /* Require and set up Horde_Form. */
 require_once 'Horde/Form.php';
 require_once 'Horde/Form/Renderer.php';
+require_once 'Horde/Variables.php';
 
 /* Get the data to be inserted, obviously with keys corresponding
    to the available fields in the form. */
 $somedata = array(.....);
 
 /* Set up this data as a new Horde_Form_Vars object. */
-$vars = &new Horde_Form_Vars($somedata);
+$vars = new Variables($somedata);
 
 /* Get formname var to check if submitted later on. */
 $formname = $vars->getVar('formname');
 
 /* Get the form object, setting the vars and the title. */
-$myform = &Horde_Form::singleton('SomeForm', $vars, _("An Example Form"));
+$myform = new Horde_Form($vars, _("An Example Form"), 'some_form');
 
 /* Set up the form fields. */
 $myform->addHidden('', 'example_hidden', 'int', false);
 $myform->addVariable(_("Foo field"), 'example_foo', 'text', true);
@@ -54,10 +55,9 @@
 }
 
 /* Render out the form and it should have the fields filled in
    according to the $somedata array values. */
-$renderer = &new Horde_Form_Renderer();
-$myform->renderActive($renderer, $vars, 'edit.php', 'post');
+$myform->renderActive(new Horde_Form_Renderer(), $vars, 'edit.php', 'post');
 </code>
 
 ----
 
@@ -79,39 +79,37 @@
 require_once 'Horde/Variables.php';
 
 $registry = &Registry::singleton();
 
-$vars = &Variables::getDefaultVariables();
-$form = &Horde_Form::singleton('', $vars, 'Using conditional enable');
-
-$params = array('target' => 'choices',
-                'enabled' => true,
-                'values' => array('other'));
-$action = &Horde_Form_Action::singleton('conditional_enable', $params);
+$vars = Variables::getDefaultVariables();
+$form = new Horde_Form($vars, 'Using conditional enable');
 
 $choices = array('big' => 'BIG',
                  'small' => 'small',
                  'other' => 'Other');
 $form->addVariable('Select something', 'choices', 'enum', true, false, '', array($choices, true));
 $o = &$form->addVariable('If other, please describe', 'other_text', 'text', false, false);
-$o->setAction($action);
+$params = array('target' => 'choices',
+                'enabled' => true,
+                'values' => array('other'));
+$o->setAction(Horde_Form_Action::factory('conditional_enable', $params));
 
 /* Render the form. */
-$renderer = &new Horde_Form_Renderer();
-$form->renderActive($renderer, $vars, 'form.php', 'post');
+$form->renderActive(new Horde_Form_Renderer(), $vars, 'form.php', 'post');
 </code>
 
 ----
 
 <code type="php">
 <?php
 require_once 'Horde/Form.php';
 require_once 'Horde/Variables.php';
+require_once 'Horde/Form/Renderer.php';
 
-$vars = &Variables::getDefaultVariables();
+$vars = Variables::getDefaultVariables();
 
 /* Set up the form object. */
-$form = &Horde_Form::singleton('', $vars, 'A simple form');
+$form = new Horde_Form($vars, 'A simple form');
 
 $form->setButtons('Submit this form', true);
 $form->addVariable('Insert some text', 'some_text', 'text', false, false, 'Insert in this box some text');
 
@@ -128,11 +126,9 @@
     echo '</pre>';
 }
 
 /* Render the form. */
-require_once 'Horde/Form/Renderer.php';
-$renderer = &new Horde_Form_Renderer();
-$form->renderActive($renderer, $vars, 'simple_form.php', 'post');
+$form->renderActive(new Horde_Form_Renderer(), $vars, 'simple_form.php', 'post');
 </code>
 
 ----
 
@@ -177,48 +173,48 @@
     }
 
 }
 
-$RENDERER = &new Horde_Form_Renderer();
-$vars = &Variables::getDefaultVariables();
+$r = new Horde_Form_Renderer();
+$vars = Variables::getDefaultVariables();
 
-$form1 = &Horde_Form::singleton('TestForm1', $vars);
-$form2 = &Horde_Form::singleton('TestForm2', $vars);
+$form1 = new TestForm1($vars);
+$form2 = new TestForm2($vars);
 
 $form1->validate($vars);
 $form2->validate($vars);
 
-/* check if one form is not valid */
+/* Check if one form is not valid. */
 if (!$form1->isValid() || !$form2->isValid()) {
     if ($form1->isValid()) {
-        $form2->open($RENDERER, $vars, 'form.php', 'post');
+        $form2->open($r, $vars, 'form.php', 'post');
 
         // preserve form1 variables
         $form1->preserve($vars);
-        $RENDERER->beginInactive($form1->getTitle());
-        $RENDERER->renderFormInactive($form1, $vars);
-        $RENDERER->end();
+        $r->beginInactive($form1->getTitle());
+        $r->renderFormInactive($form1, $vars);
+        $r->end();
 
         // now render the active form
-        $RENDERER->beginActive($form2->getTitle);
-        $RENDERER->renderFormActive($form2, $vars);
-        $RENDERER->submit();
-        $RENDERER->end();
-        $form2->close($RENDERER);
+        $r->beginActive($form2->getTitle);
+        $r->renderFormActive($form2, $vars);
+        $r->submit();
+        $r->end();
+        $form2->close($r);
     } else {
-        $form1->open($RENDERER, $vars, 'form.php', 'post');
+        $form1->open($r, $vars, 'form.php', 'post');
 
-        $RENDERER->beginActive($form1->getTitle());
-        $RENDERER->renderFormActive($form1, $vars);
-        $RENDERER->submit();
-        $RENDERER->end();
+        $r->beginActive($form1->getTitle());
+        $r->renderFormActive($form1, $vars);
+        $r->submit();
+        $r->end();
 
-        $form1->close($RENDERER);
+        $form1->close($r);
     }
 } else {
     $form1->getInfo($vars, $info);
     $form2->getInfo($vars, $info);
-    echo "<pre>";
+    echo '<pre>';
     print_r($info);
-    echo "</pre>";
+    echo '</pre>';
 }
 </code>


More information about the cvs mailing list