[dev] Form.php and enum fields

Chuck Hagenbuch chuck at horde.org
Wed Jan 8 16:41:36 PST 2003


Quoting Marko <marko at oblo.com>:

> i'll see what i can do about a patch to allow some form of "label" within
> the select field. i think it would be useful, what do you reckon?
> doing a custom form renderer just to get one "Choose one:" label is too
> much.

I get no "field is required" problems with this code:

<?php

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 {

    var $_useFormToken = false;

    function TestForm(&$vars)
    {
        parent::Horde_Form($vars);

        $etype = _getEnumType(array('' => _("Select:"),
                                    1 => _("Yes"),
                                    0 => _("No")));
        $this->addVariable(_("Enum"), 'enum', $etype, true);
    }

}

_useForms(array('TestForm'));

$r = &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';
    }
}
$form->renderActive($r, $vars, 'form.php', 'get');


-chuck

--
Charles Hagenbuch, <chuck at horde.org>
must ... find ... acorns ... *thud*


More information about the dev mailing list