// Load the customer object $customer = Mage::getModel('customer/customer')->load($customerId); // Create the form object $form = new Varien_Data_Form(); // Add the form fields $field1 = $form->addField('name', 'text', array('label' => 'Name')); $field2 = $form->addField('email', 'text', array('label' => 'Email')); // Pre-fill the form fields with customer data $form->addValues(array( 'name' => $customer->getName(), 'email' => $customer->getEmail(), ));
// Load the object $data = MyObject::load($objectId); // Create the form object $form = new Varien_Data_Form(); // Add the form fields dynamically foreach ($data->getFields() as $field) { $form->addField($field->getName(), $field->getType(), array('label' => $field->getLabel())); } // Pre-fill the form fields with object data $fieldData = array(); foreach ($data->getFields() as $field) { $fieldData[$field->getName()] = $data->getFieldValue($field->getName()); } $form->addValues($fieldData);In both examples, we're using the Varien_Data_Form class to create a form object, add fields to it, and pre-fill those fields with data using the addValues() method. This class is part of Magento's core library and is located in the Varien package.