How do I create a birthday form for registration in Zend Framework?
I am trying to create a drop down for birthday. I want 3 different drop downs (1 for month, 1 for date, 1 for year). I understand how to do it separately, but I don't know what's the best way to combine them, so I can stor开发者_开发百科e it in 1 field in MySQL.
You should look at Composite Elements which are multiple form elements that are rendered, and validated together as one.
The example there is a birthday element similar to what you want except they use text fields instead of dropdowns to simplify things. If you look at that example you should be able to create one using select elements instead of text elements. Also, check out this blog post from Matthew Weier O'Phinney (ZF project lead) on creating composite elements. He does the same birthday example from the ZF reference guide, but may be helpful as well. Some of the user comments on there may be helpful as well.
If it all seems like too much work for now, you can render them as separate elements and "put them together" in your controller/form validation routines, and insert it into the database as a single value (YYYY-mm-dd), and then when you read back from the database, you can split that up and populate each individual select element with their respective date parts.
This wouldn't be the best way, but if you are beginning with Zend Framework, creating composite elements, decorators and validators can be a daunting task at first.
精彩评论