Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-03-28 19:49:20

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

ZC51 – Encapsulating Business Rules with Zend_Validate

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.

Offline

#2 2010-03-30 23:18:31

kobescoresagain
New member
Registered: 2010-02-24
Posts: 2

Re: ZC51 – Encapsulating Business Rules with Zend_Validate

Jon,

I was curious how you would do this with Zend_Form_Dojo fields.  Does it work the same?

Offline

#3 2010-03-31 17:53:10

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: ZC51 – Encapsulating Business Rules with Zend_Validate

Hey Kobe,
I'm afraid I don't have experience with Zend_Form_Dojo, however I imagine that it would also work with Dojo forms...

Offline

#4 2010-04-05 11:07:59

ulduz114
New member
Registered: 2010-02-24
Posts: 4

Re: ZC51 – Encapsulating Business Rules with Zend_Validate

hello jon

i created a custom element(phone) as you taught, i could save value of this element to database, but i could not read and show in this custom element for edit..

i used same this in model

public function findCustomerPhone($id){

        phone = $this->find ( $id )->current ();
        return $phone->toArray();

    }

and same following code in my controller
function edit(){

.
.
.
          $id = $this->_request->getParam ( 'id' );
      $customer = $customerModel->findCustomerPhone($id);
    $frmcustomer->populate ( $customer );
}

i can see other fields in my form but i can not see phone value

how can i populate this element value  from database to form ?

thanks

Last edited by ulduz114 (2010-04-05 11:09:32)

Offline

#5 2010-04-06 18:19:52

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: ZC51 – Encapsulating Business Rules with Zend_Validate

Hey Ulduz,

The populate method is probably going to run the setValue() method on the form element. This is assumed to be a string, however you're returning an array from findCustomerPhone()

Offline

#6 2011-07-31 11:56:38

ryy705
New member
Registered: 2011-07-31
Posts: 1

Re: ZC51 – Encapsulating Business Rules with Zend_Validate

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);

Offline

#7 2011-07-31 14:54:43

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: ZC51 – Encapsulating Business Rules with Zend_Validate

Hi ryy705, you could use a foreach, create an array and then loop through those lines with the given keys... (e.g. array('Direct Number' => 'directphone', etc...) )

Offline

Board footer

Powered by FluxBB