Parameters of Varien_Data_Form?

Why do I write this? Because I had the problem a few hours ago that no form was rendered in my backend formular. And as a few of you may know, the FireGento GermanSetup Team met today. Noone of us knew instantly why. So here are a few tipps.

HTML Attributes

You can set the html attributes id, name, method, action, enctype, class and onsubmit. Especially method and enctype is needed for file uploads. With onsubmit you can implement more checks in javascript. And with action the target of the form is defined, as you should know.

Container yes or no?

As you can see in the code there is another parameter: use_container. With use_container you decied wether to wrap a <form> around your form elements and add a form_key.

EAV attributes, default values and source models

EAV Attribute

I tried to add an EAV attribut, set a default value and that without using a source model, set this options:

$this->addAttribute('customer', 'customer_type', array(
    'type' => 'int'     
    'option' => array('values' => array('Customer', 'Artist'))
    'default' => 'Customer',
    [...]
);

Default value

Magento adds the values into the eav_attribute_option_value table and shows them in the backend. The problem is, if we save them as int, we can't set 'Customer' as default. And we can't set the eav_attribute_option_value.value_id, because we don't know it.

Solution

I removed the options from the attribute and added a soure model.

$this->addAttribute('customer', 'customer_type', array(
    'type' => 'int'     
    'source' => 'company_extension/entity_attribute_source_modelName',
    'default' => 1,
       [...]
);

A source model needs to implement the Mage_Eav_Model_Entity_Attribute_Source_Interface. To make life easier there is an abstract class Mage_Eav_Model_Entity_Attribute_Source_Abstract we can extend.

So just implement the source model, then you know the int value of your options and you can set it.