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

Wiki Guest wiki at wiki.horde.org
Tue Jul 5 18:49:30 PDT 2005


guest [207.172.212.178]  Tue, 05 Jul 2005 18:49:30 -0700

Modified page: http://wiki.horde.org/Doc/Dev/FormPackage
New Revision:  1.5
Change log:  add conditionl_enable action

@@ -1,5 +1,7 @@
 + Horde_Form
+
+[[toc]]
 
 ++ 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.
@@ -50,8 +52,49 @@
 /* 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');
+</code>
+
+----
+
+++ Using Horde_Form_Action
+
+Here's an example that uses the conditional_enable action to enable a text description if the user picks "Other".
+
+<code type="php">
+<?php
+/**
+ * Example for the conditional_enable action.
+ */
+
+ at define('HORDE_BASE', dirname(__FILE__));
+require_once HORDE_BASE . '/lib/core.php';
+require_once 'Horde/Form.php';
+require_once 'Horde/Form/Action.php';
+require_once 'Horde/Form/Renderer.php';
+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);
+
+$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);
+
+/* Render the form. */
+$renderer = &new Horde_Form_Renderer();
+$form->renderActive($renderer, $vars, 'form.php', 'post');
 </code>
 
 ----
 


More information about the cvs mailing list