[dev] Form example patch

Eduardo Dominguez lalo at teligens.com
Mon Mar 31 11:26:32 PST 2003


Recently I requested some help with the Form class and Chuck committed a 
an example to CVS. Recently there where some changes to the Form class 
and I decided to update the example on CVS to make use of the changes 
and in the process added more functionality to the example as to make it 
more self explanatory. Now instead of one form, the example is a two 
step form.

Here is the patch.
-------------- next part --------------
Index: form.php
===================================================================
RCS file: /repository/hordedoc/developer/work/form.php,v
retrieving revision 1.1
diff -u -p -r1.1 form.php
--- form.php	14 Mar 2003 03:27:40 -0000	1.1
+++ form.php	31 Mar 2003 16:49:51 -0000
@@ -4,34 +4,84 @@ define('HORDE_BASE', '/var/www/horde');
 require_once HORDE_BASE . '/lib/Form.php';
 require_once HORDE_BASE . '/lib/Form/Renderer.php';
 
-class TestForm extends Horde_Form {
+class TestForm1 extends Horde_Form {
 
     var $_useFormToken = false;
 
-    function TestForm(&$vars)
+    function TestForm1(&$vars)
     {
-        parent::Horde_Form($vars);
+      parent::Horde_Form($vars, _("Step 1"));
 
-        $etype = _getEnumType(array('' => _("Select:"),
-                                    1 => _("Yes"),
-                                    0 => _("No")));
-        $this->addVariable(_("Enum"), 'enum', $etype, true);
+        $enum = array('' => _("Select:"),
+																1 => _("Yes"),
+																0 => _("No"));
+        				
+        /*     addVariable( Visible Text, name, type, required, readonly, description, params) */
+        $this->addVariable(_("Enum"), 'opciones', 'enum', true, false, _("Simple description"), array($enum));
+        $this->addVariable(_("Boolean"), 'bool', 'boolean', false, false );
+        $this->addVariable(_("Integer"), 'number', 'int', true, false );
+        $this->addVariable(_("A Date"), 'mybday', 'date', false, false );
     }
+}
+
+class TestForm2 extends Horde_Form {
 
+    var $_useFormToken = false;
+	
+    function TestForm2(&$vars)
+		{
+        parent::Horde_Form($vars, _("Step 2"));
+	
+        $this->addVariable(_("Email"), 'email_address', 'email', true, false );
+		}
 }
 
-_useForms(array('TestForm'));
 
-$r = &new Horde_Form_Renderer();
+_useForms(array('TestForm1','TestForm2'));
+
+
+$RENDERER = &new Horde_Form_Renderer();
 $vars = &Horde_Form::getDefaultVars();
-$form = &_getTestForm($vars);
 
-if ($vars->getVar('formname')) {
-    $form->validate($vars);
-    if ($form->isValid()) {
-        echo 'valid data';
-    } else {
-        echo 'invalid data';
-    }
+$form1 = &_getTestForm1($vars);
+$form2 = &_getTestForm2($vars);
+
+$form1->validate($vars);
+$form2->validate($vars);
+
+/* check if one form is not valid */
+if (!$form1->isValid() || !$form2->isValid()) {
+  if ($form1->isValid()) {		
+        $form2->open($RENDERER, $vars, 'form.php', 'post');
+        
+        // preserve form1 variables
+        $form1->preserve($vars);
+        $RENDERER->beginInactive($form1->getTitle());
+        $RENDERER->renderFormInactive($form1, $vars);
+        $RENDERER->end();
+        
+        // now render the active form			
+        $RENDERER->beginActive($form2->getTitle);
+        $RENDERER->renderFormActive($form2, $vars);
+        $RENDERER->submit();
+        $RENDERER->end();
+        $form2->close($RENDERER);
+
+		}else{
+		
+        $form1->open($RENDERER, $vars, 'form.php', 'post');
+        
+        $RENDERER->beginActive($form1->getTitle());
+        $RENDERER->renderFormActive($form1, $vars);
+        $RENDERER->submit();
+        $RENDERER->end();
+        
+        $form1->close($RENDERER);
+		}
+}else{	
+    $form1->getInfo($vars, $info);
+    $form2->getInfo($vars, $info);
+    echo "<pre>";
+    print_r($info);
+    echo "</pre>";
 }
-$form->renderActive($r, $vars, 'form.php', 'get');


More information about the dev mailing list