In this video, we’re going to work on building a custom validator for our composite form element for phone numbers. The nice thing about this validator is that it can then be applied to any sort of textbox. Next week, we’ll ajaxify our final form with a handful of lines of jQuery.
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”.

Great video thanks:)
Hello, excellent the video tutorial, I’m using the code on a form of Access to a mysql database, I find it good to save the data, but I want to edit the data load for the composition field of some help please.
Thanks
Hey, Thanks for making my morning a little bit better with this great article!!
Is there a way to get a validator to fire even if the form element isn’t required? I have a form where I want to validate the contents of a texbox (make sure not empty) if the value of another form element, which is a couple of radio buttons, has a specific value selected. I’m using a custom validator but it never seems to get fired unless I set the field to required (which I don’t want it to be all the time).
Great video, thanks!!
I’ve used it to help me build and validate a national insurance form element.
I’ve been trying to apply a ‘StringToUpper’ filter to the composite element but it doesn’t work like it does on a standard element.
Can you point me in the right direction?
Hi Jon!
Thank you very-very much for these videos, they are awesome! So is this one, I just wish you didn’t use ereg_replace as that is deprecated as of PHP 5.3.0. Keep up the awesome work you do otherwise, I’m off to visit your supporters now.
Hello Jon,
I found this screencast to be very helpful. But how do I generate more than one phone element in the same form? The following create six fields for the second phone element:
$cellPhone = new ZC_Form_Element_Phone(‘phone’);
$cellPhone->addValidator(new ZC_Validate_CellPhone());
$cellPhone->setLabel(‘Cell Number:’)->setRequired(true);
$directPhone = new ZC_Form_Element_Phone(‘directphone’);
$directPhone->addValidator(new ZC_Validate_CellPhone());
$directPhone->setLabel(‘Direct Number:’)->setRequired(true);
Hey there,
first of: Thank you for this awesome website. This is likely to be the best resource for me having trouble with any sorts of ZF related problems. Great learning resource.
I used all the teachings from this series for creating an IP-Element.
With this i noticed a little flaw in your code – or let’s better say in PHP
You check like this:
function getValue() {
if(!$var || !var || !var) { return false }
return $var.$var.$var;
}
And that’s bad, because in an IP-Adress for example you will need to allow the “0″ – but 0 in php is equal to false.
So it would be better to check for
is_null($var) instead of !$var
That’s the way i solved my little problem at least.