Issue Type: Improvement Created: 2007-04-18T14:40:49.000+0000 Last Updated: 2008-03-21T16:25:31.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)
Reporter: Dawid Zamirski (maners) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_View
Related issues: - ZF-1639
Attachments: - FormElement.php.patch
This is just an idea, so I'm not proposing any code yet until you consider it valuable :-) I think it would be useful to be able to pass an array as the $value argument to any form helper because it will automate the process to generate universal forms for adding/editing records e.g
<pre class="highlight"> $post = $this->_request->getPost(); $this->formText("first_name", $post);
This code would generate a blank field if $post is null or insert the $post['first_name'] value if it's available. It's a common practice (at least for me) to have the same xhtml form for adding and editing certain records. Therefore, the ability to pass an array as $value, which then would lookup the element that matches $name, would definitely simplify creation of such forms. Please let me know what you think about this and I'll write the code if you agree :-)
Posted by Dawid Zamirski (maners) on 2007-06-11T10:45:58.000+0000
Attached is a patch against SVN trunk which enables $value argument to be an array from which it attempts to extract data for the value XHTML attribute. The $value array must contain a key matching $name and, if it does not, blank ('') value is used instead. This patch doesn't change behavior of existing API and it just adds the new functionality. I have used it for a few weeks with one of my projects and it didn't cause any problems.
Posted by Matthew Weier O'Phinney (matthew) on 2007-11-16T10:33:36.000+0000
I've scheduled this for the 1.1.0 release, which will include a number of other view helper changes as well.
Posted by Matthew Weier O'Phinney (matthew) on 2008-01-29T14:06:12.000+0000
I've just re-read the issue, and I don't agree with the implementation; if you can pass an array containing the element name as a value, you can certainly pass the specific key in the element:
<pre class="highlight"> $this->formText('first_name', $post['first_name']);
If you're worried that the element name is not in the array, then you should pre-initialize the array, or use a ternary:
<pre class="highlight"> $this->formText('first_name', ((isset($post['first_name']) ? $post['first_name'] : ''));
Yes, it's more verbose, but it's also more explicit and doesn't lead to unexpected results.
Now, if you want support for array syntax in the element names, that's another matter.
Posted by Matthew Weier O'Phinney (matthew) on 2008-03-06T09:40:18.000+0000
Array notation works already, and solutions using existing functionality have been provided in comments.
Have you found an issue?
See the Overview section for more details.