This video should help you build your own composite Zend_Form element. We’ll be building a phone element. The phone element will have 3 textboxes, one for geographic location, area code and local code. In the following videos will add a custom cell phone validator and some ajax validation.
Grab a copy of the project or browse the repository.
ServerGrove has offered to sponsor 3 videos in March! ServerGrove specializes in Zend Framework hosting and they’ve offered a 10% rebate on hosting with coupon code “zc”. If you’re looking for a host, be sure to check them out (referral). They’ve also added an additional coupon for “Mini Hosting” plans, get $2 off by using code “zcmini”.

Didnćt watch the screen, but according to google code I think http://code.google.com/p/zendcasts/source/browse/trunk/zc49-composite-form-elements/library/ZC/Form/Element/Phone.php need getValue)= method override.
Zend_Form_Element_Xhtml extends from Zend_Form_Element, which implements Zend_Validate_Interface as well as the getValue() method. In the next video, I’ll be writing our own method override and using a string delimiter rather than an array.
Thanks Jon.
I’m looking forward to the next installment, I’ve seen other composite elements that use a decorator to render, I’m curious which method is better (view vs. decorator).
Thanks for the tutorial, helped me to clarify several aspects while coding an autocomplete custom form element for an application. One remark though: in the composite element’s view helper, the protected “$html” variable must be reset to an empty string inside the helper’s method, because if you want to use more than one “phone” element in the same form, the new $html content will be appended to the old one with each new element – I suppose the helper class is instantiated once and re-used after when necessary (this make the $html persistent and thus must be reset). Anyway great video, thanks a lot!
hello everyone , i hope you can read this before you work with the code ..
http://www.zendcasts.com/forum/post/790/#p790
Great video, thanks so much! Really cleared up a lot of questions I had about form elements…
Hi,
Another great “non-expected”
tutorial.
Doing this with the “ajaxLink()” helper is also quite simple.
Fabrice
I get a XHTML Strict warning:
line 62 column 36 – Informatie: reference to non-existent ID “phone”
This is because “Cell Number:” has a reference to a non-existent ID “phone”.
How do I fix this?
Thanks for the tutorial. I implemented something like this for a user’s social security number and it worked great.
My question though is how would you Unit Test this?
I’ve tried to write a unit test to pass valid and invalid data to the form but I can’t figure out how the data should be formatted (in the @dataProvider function) to be inserted into the setPost function.
Thanks.
Hi Jon,
Great website you have. I’m wondering how to create something like this for a date picker with select boxes (and avoid JavaScript) because I only need to have a specific date range.
When I change the FormText to FormSelect I’ll get some select form elements but I need to add some options to it. I can’t do it with:
$this->html .= $helper->formSelect($name.’[day]‘,$day,array())->addMultiOption(”, ‘– Pick a day –’);
Do you have any suggestions?