Matthew Weier O'Phinney schreef:
-- Fire Eye'd Boy <[email protected]> wrote
(on Wednesday, 01 April 2009, 10:49 PM +0200):
Matthew Weier O'Phinney schreef:
-- fire-eyed-boy <[email protected]> wrote
(on Wednesday, 01 April 2009, 10:54 AM -0700):
Eventhough I see it's use; in my current setup, setElementsBelongTo()
doesn't offer me the solution I was hoping for. But maybe I am overlooking
something.
Yep. You're using the ViewScript decorator to render your elements, so
you need to do a couple of things manually.
First, for each element, you need to do the following:
// simplified -- you should refactor to cache the form name
$element->setBelongsTo($form->getElementsBelongTo());
This is done implicitly in the FormElements decorator -- but since
you're using ViewScript on your form, you have to do it manually. I
would do this at the start of my view script before rendering anything,
using something like this:
$belongsTo = $this->element->getElementsBelongTo();
foreach ($this->element->getElements() as $element) {
$element->setBelongsTo($belongsTo);
}
Second, when rendering your elements, if you don't use the ViewHelper
decorator, you'll need to fetch the name and/or ID manually:
$element->getFullyQualifiedName(); // gets the fully qualified name
$element->getId(); // will use the FQN to create the id
Thanks for the response.
Ok, this basically solves my first problem. But to tell you the truth
this doesn't stray too far from generating my own unique id's. Although
your example is slightly more elegant.
The thing is, unfortunately this doesn't solve my second problem. That
is, how to automatically validate the form(s) in my Controller.
Let's say I've generated 10 delete forms with their own namespaces (like
you demonstrated) based on my generic form. In my controller I then need
some way to automatically detect the namespaces again.
Why not put this information in the session? You could use
FlashMessenger to store the form namespace, and then retrieve it on the
next request to determine what namespace to pull out of the posted data.
Matthew,
Thanks for your help. But I ended up creating my unique id's after all.
The thing was: the CMS I'm building shows a pagetree with multiple forms
for each page in the pagetree. So each page item has about five forms
(edit, sort-up, sort-down, delete, show-in-navigation).
Each page item uses a generic form for each of these distinct options.
Something like this (but with nested levels too):
- Page 1 [form show] [form down] [form up] [form delete] [form edit]
- Page 2 [form show] [form down] [form up] [form delete] [form edit]
- Page 3 [form show] [form down] [form up] [form delete] [form edit]
etc...
If I where to keep track of each namespace of these options for each
page item in the tree, like you suggested, it would get very sloppy. I
think you must have misintepret my intentions. Because these form all
reside in one and the same page.
Anyway, all is working like a charm now. Thanks for you help though.
Much appreciated.
Cheers
<snip>