I have created one form that extends zend form. For Adding New Record it works fine. But I want the same form to work for update record. So the form fields get set for the record being edited? What is the best practice for such cases?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to reuse forms, it’s pretty simple:
don’t put the action in your form, assign the the action in your controller
$form->setAction('/path');(this will also override the action you set in the form)Remove any form elements not required by the current purpose, typically an add form will have a few more elements then an update form.
$form->removeElement('elementName');Change any labels that need changing.
$form->submit->setLabel('Update');prepopulate the form with data.
$form->populate('dataArray');Then just process the form as usual.