Magento – How to rearrange form fields for customer address attributes in the admin

addressadminhtmlcustomerforms

I am developing a Magento extension that adds several custom attributes to the customer address. My goal is to rearrange the address input fields in the admin order form. When I change the sort order of the attributes, the arrangement changes, but only for the custom attributes. I.e. I cannot place input field for custom attribute before input field for a system attribute.

I've read the source code in Mage_Adminhtml_Block_Sales_Order_Create_Form_Address and Mage_Customer_Model_Form but still cannot figure out how to do it.

Is this possible at all? If so, how do I achieve it?

Edit
In my mysql4-install-0.1.0.php script, I use:

$this->addAttribute('customer_address', 'carrier_office_name', array(
    'type' => 'int',
    'input' => 'text',
    'label' => 'Carrier office name',
    'global' => 1,
    'visible' => 1,
    'sort_order' => 247, // example
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1
));

Best Answer

Take a look at the code found in Mage_Adminhtml_Block_Sales_Order_Create_Form_Address::_prepareForm. After it calls _addAttributesToForm to add all the attributes, it does extra processing on a handful of the default attributes. When it does this, it is removing them from the form, then adding them back in after '^' which will put them at the top of the form regardless of their original position.

It is certainly possible to alter the positioning of all the attributes in the form, but to do so you will need to extend the block in order to control the final positioning of the form elements.