views:

138

answers:

2

i have some fields in my database table,and a field with phone name , i save value to this filed like this 111-222-5555

now i want to read all of my fields , and populate to my form , i like populate phone filed to 3 elements(as text element)

when i try this code

$id = $this->_request->getParam ( 'id' );
$values = $cutomModel->findCustomerById($id);// return array of row 
$frm->populate($values); 

all fields show in form except phone field ,

how can i populate phone field to 3 elements

thanks

A: 

From what I (hardly) understood, you are trying to fill 3 elements of a form with the content of one field (phone) in your database table.

To achieve this you can use the setDefault() method of the Zend_Form object. Something like this:

$frm->setDefault('field_name', $values->phone);

Do this after populate() and for every field that you want a customized value to be filled.

rogeriopvl
it dose not work
user1400
A: 

If I understand your question correctly, firstly you need to create 3 separate form fields (something along the lines of phone_1, phone_2 and phone_3) to hold the 3 separate phone segments. Then before populating the fields, separate the database output of 1 field into 3 fields.

$id = $this->_request->getParam ( 'id' );
$values = $cutomModel->findCustomerById($id);// return array of row 

// split phone number into 3 values
list($values['phone_1'], $values['phone_2'], $values['phone_3']) = explode('-', $values['phone'], 3);

$frm->populate($values); 

Finally, before inserting form input into your database you must combine the input from the 3 fields into 1 field.

$values = $frm->getValues();

// combine phone number into 1 value
$values['phone'] = implode('-', $values['phone_1'], $values['phone_2'], $values['phone_3'])

$cutomModel->insert($values);
Dan