Maybe I'm not understanding the ViewScript decorator, so please help clarify if my thinking is not correct. I've tried Matthew's rough test code below and looked through the ViewScript decorator file. I can totally see using it for an Element Decorator. But... I'm failing to see any true benefit of using it as a Form Decorator (as Matthew has described). What's the benefit of using it on a form? You go from <?= $this->form ?> to having to create a new partial file which then has to iterate through all of the elements. You can't use <?= $this->element ?> (actually kills my app - *exit signal Illegal instruction (4)*). On top of that, you have to insert logic or manually place each of the elements to get "custom" messages to appear where you want. I don't see this as much easier than hardcoding an HTML form or just iterating through the form object in the main view script and just doing whatever display options you want.

Quick Question : Do elements have a toString() method to render the HTML for just that element? That would at least make it easier to step through the elements.

Anyways. I have seen other requests similar to Alexis' and I do see how it could be useful. Maybe a new Null or String element type. So, instead of Alexis' subject of 'Position form elements in HTML', we'd be trying to insert markup elements into the form, somehow. Basically, you could add this "new" element into your form, but its only real purpose is to insert markup. It could have properties similar to other form elements (label, description) but "value" would just be markup that got displayed. Using Alexis' example, the elements could be:

'myinput' => array('text', array(
   'label' => 'MyGreatLabel'
)),
'notamenuandnotaform' => array('newnullorstringelement', array(
   'value' => '<div id="notamenuandnotaform"><ul><li>1</li>...</div>'
)),
'anotherinput' => 'text',
etc...

This way, it would be easy to generate the form and messages in one <?=$this->form?>, everything would be formatted together, gand lobal CSS would apply nicely.

I have also seen questions regarding being able to output the value of the element instead of the markup via a flag or something. That could be highly useful and that could accomplish the same thing. So, you could just insert a textarea element and fill the value with the markup you want outputted. Then, toggle the "flag" on the element to just dump the value instead of creating the markup. I can see this as useful for form re-use cases (confirmation pages, pages to edit data where some fields are NOT editable, etc.). Decorators could still apply. Of course, the dump would be intuitive for text and textarea elements, but for the other elements, the output would have to be "decorated" appropriately. Actually, I think this is a much more usuable way to do it than the new element idea above...But anyways... :-)

Arthur


Matthew Weier O'Phinney wrote:
-- Alexis von Glasow <[EMAIL PROTECTED]> wrote
(on Thursday, 28 February 2008, 08:27 AM -0800):
I would like to separate all elements of my form into my page. Maybe I have
missed something, but I have read the doc and i have not found anything. How
can I do this with Zend Form

For exemple: I would like to obtain this kind of result.

<html>
<head>
</head>
        <body>
                <form name="myBigForm">
                        <input type="submit" />
                        <label>MyGreatLabel</label><input type="text" 
name="myinput" />
                        <div id="notamenuandnotaform">
                                <ul>
                                        <li>1</li>
                                        <li>2</li>
                                        <li>3</li>
                                <ul>
                        </div>
                        <input type="text" name="anotherinput"/>
                        <textarea rows="3" cols="20"></textarea>
                        <div id="plop">
                                <p>any content</p>
                        </div>
                        <input type="text" name="inputagain" />
                </form>
        </body>
</html>

I'd personally use the ViewScript decorator here. With it, you could
render any markup you want, have access to your form and/or individual
elements (and potentially use the element decorators when rendering, or
simply pull data from them to determine how to do the markup), etc.

Modify your form to use the ViewScript decorator:

    $form->setDecorators(array(array(
        'decorator' => 'ViewScript',
        'options' => array('viewScript' => 'myForm.phtml')
    )));

Then, in your view script ('myForm.phtml'):

    <? $form = $this->element ?>
    <form name="myBigForm">
        <?= $form->submit // render your submit element ?>
        <label>MyGreatLabel</label><input type="text" name="<?= $form->myinput->getName() 
?>" />
        ...
    </form>

Hopefully, that gives you enough to start with.

Reply via email to