Page 1 of 1

Automatic form generation suggestion...

Posted: Fri Apr 06, 2007 12:49 pm
by powerful0x0
Hello,

I'm looking forward to make developing forms easier for me.. and so i have done some researchs and ended up with these two frameworks:

patForms: http://trac.php-tools.net/patForms
PHPClasses.orgForm Generation: http://www.phpclasses.org/browse/package/1.html

both are good... but i love patForms more, and it has excellent documentation.. but it seems it's not supported that well or bit neglected in another word.

My question.. Do you have any other suggestions like the above? i would approciate it and what do you think about the above frameworks?

Thanks in advance,
Samer

Posted: Fri Apr 06, 2007 12:55 pm
by Luke
There's always HTML_QuickForms

Posted: Fri Apr 06, 2007 7:11 pm
by John Cartwright
I myself have been on a long journey to simplify the creation of forms. However, many people, including myself, have come to the conclusion that it is simply much easier to simply write the forms by hand than having to a simple library to deal with the inherintly complex task of form generation.

Posted: Sat Apr 07, 2007 4:44 pm
by Luke
unless of course you have some reasonably simple forms. I still use HTML_QuickForm on my projects, but it is definitely not ideal. I don't even use the renderer because I just really don't think my form validator has any business rendering my form ( :? ). I like having 100% control over my html. I build the form html on my own and integrate a whole seperate system for error reporting using views and view helpers. Something along the lines of...

Form controller function

Code: Select all

public function _processDataAdd()
    {
        $form = new HTML_QuickForm('add_calendar');
       
        $title = new HTML_QuickForm_text('calendar_title');
        $form->addElement($title);
               
        $description = new HTML_QuickForm_textarea('calendar_description');
        $form->addElement($description);
               
        $admin_must_allow = new HTML_QuickForm_text('calendar_admin_must_allow');
        $form->addElement($admin_must_allow);
       
        $form->applyFilter('__ALL__', 'trim');
       
        $form->addRule('calendar_title', 'This is required', 'required');
        $form->addRule('calendar_title', 'This cannot be over 100 characters', 'maxlength', 100);
       
        $form->addRule('calendar_description', 'This cannot be over 5000 characters', 'maxlength', 1000);
       
        return $this->_processForm($form);
    }
Application Controller:

Code: Select all

protected function _processForm(HTML_QuickForm $form, $include_wrap = true)
    {
        if ($form->validate())
        {
            return $form;
        }
       
        $errorPrefix = '';
        $errorSuffix = '';
       
        if ($include_wrap)
        {
            $errorPrefix = '<span class="error">';
            $errorSuffix = '</span';
        }
       
        foreach ($form->_elements as $element)
        {
            $error = $form->getElementError($element->getName());
            if (!empty($error))
            {
                $this->_view->setFormError($element->getName(), $errorPrefix . $this->_view->escape($error) . $errorSuffix);
            }
            $this->_view->setFormValue($element->getName(), $form->exportValue($element->getName()));
        }
        return false;
    }

Code: Select all

<?php if ($this->formIsError()): ?>
     <div class="alertError">One ore more fields were not filled out correctly. Please revise and submit again.</div>
    <?php endif; ?>

    <div><label> Event title</label><?php echo $this->formCheckbox('event_title', $this->formValue('event_title')); ?></div>

    <div><label> Event description</label><?php echo $this->formCheckbox('event_description', $this->formValue('event_description')); ?></div>

<!-- and so on... -->

Posted: Sun Apr 08, 2007 12:14 pm
by powerful0x0
Thanks for your responses...

no matter the automatic generation seems bit not under control but in my openion it's very good choice for maintaining web forms and their heaches, i guess you know all the silly errors that could happen while doing a form...


Smarty & Quickforms seems to be a very good solution if you know how to use it.

Checkout this link.. maybe its looks like more programming but this is much easier to maintain when you are working with many forms.

http://davidmintz.org/presentations/sho ... and_Smarty