Thanks for that I will try it.

 

In my database I am storing the values as char(1) strings, one of the
following;

 

C, P, B or W.

 

Would it be a better design and simpler to implement if I store the values
as integers, as one of the following;

 

0, 1, 2, 3. (I am assuming this would be a zer based array?)

 

I'm really new to HTML, PHP and Zend Framework, so forgive me if these are
really stupid questions.

 

Steve R

 

From:
fw-general-return-30149-srayner=williams-refrigeration.co...@lists.zend.com
[mailto:fw-general-return-30149-srayner=williams-refrigeration.co...@lists.z
end.com] On Behalf Of Hector Virgen
Sent: 04 August 2009 21:04
To: Steve Rayner
Cc: [email protected]
Subject: Re: [fw-general] Zend_Form_Element_Select - Set selected value from
DB row.

 

You need to use the value of the select option, not the label. So your $data
array should look like this:

 

$data = array(

            'id'         => $row->GetId(),

            'machinetype'=> 3,

            'name'       => $row->getName(),

            'descr'      => $row->getDescr()

            );

 

This is consistent with how the values will be submitted when posting the
form.


--
Hector



On Tue, Aug 4, 2009 at 12:37 PM, Steve Rayner
<[email protected]> wrote:

Should i be able to simply use $form->populate($data); to set the selected
item of a Zend_Form_Element_Select object?

 

I have this in the form;

 

// Add the machine type element

        $this->addElement('select', 'machinetype', array(

            'id'         => 'text',

            'multiOptions' => array('Cutting', 'Punching', 'Bending',
'Welding'),

            'label'      => 'Type:',

            'required'   => true,

            'filters'    => array('StringTrim','StringToUpper'),

            'validators' => array(array('StringLength', false, array(0,1)))


        ));

 

Then I have this in the controller;

 

$data = array(

            'id'         => $row->GetId(),

            'machinetype'=> 'Welding', //$row->getMachinetype(),

            'name'       => $row->getName(),

            'descr'      => $row->getDescr()

            );

            $form->populate($data);

            $this->view->form = $form;

            return;

 

However when using the controller the 'machinetype' always gets set to
'Cutting'. i.e. the first item in the list, when it should get set to
'Welding'.

 

Is $form->populate() not enough?

 

Steve R

Williams Refrigeration is a trading name of AFE Group Limited.
Registered in England & Wales under Registered Number 3872673. Registered
Office Address - Bryggen Road, North Lynn, Industrial Estate, Kings Lynn,
Norfolk, PE30 2HZ

Williams Refrigeration reserves the right to block any email attachment we
deem inappropriate and to also reject any inbound connections from
Blacklisted servers. Any email meeting the above criteria will be
automatically rejected without notification given to the original sender.

NOTE: In accordance with the Data Protection Act compliance, all Bulk sends
should use the BCC field as much as possible.

This e-mail and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you have received this email in error or are having trouble sending email
to Williams please notify the system administrator -
[email protected]

Any views or opinions expressed in this e-mail are those of the sender and
do not necessarily coincide with those of Williams Refrigeration or the AFE
Group.

 


Williams Refrigeration is a trading name of AFE Group Limited.
Registered in England & Wales under Registered Number 3872673.  Registered
Office Address - Bryggen Road, North Lynn, Industrial Estate, Kings Lynn, 
Norfolk, PE30 2HZ

Williams Refrigeration reserves the right to block any email attachment we deem 
inappropriate and to also reject any inbound connections from Blacklisted 
servers. Any email meeting the above criteria will be automatically rejected 
without notification given to the original sender.

NOTE: In accordance with the Data Protection Act compliance, all Bulk sends 
should use the BCC field as much as possible.

This e-mail and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. If 
you have received this email in error or are having trouble sending email to 
Williams please notify the system administrator - 
[email protected]

Any views or opinions expressed in this e-mail are those of the sender and do 
not necessarily coincide with those of Williams Refrigeration or the AFE Group.

Reply via email to