To add new field in admin user form, first of all you need to create a new column in admin_user
table.
app/code/local/{Namespace}/{Module}/sql/{module_setup}/mysql4-install-{version}.php
<?php
/* @var $installer Mage_Customer_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$user = $this->getTable('admin/user');
$installer->run("
ALTER TABLE $user ADD `mobile` varchar(255) NOT NULL
");
$installer->endSetup();
Then you need to observer adminhtml_block_html_before
event to add new field in admin user form.
app/code/community/{Namespace}/{Module}/etc/config.xml
<?xml version="1.0"?>
<config>
...
<adminhtml>
...
<events>
<adminhtml_block_html_before>
<observers>
<event_column_append>
<type>model</type>
<class>{your-observer-class}</class>
<method>addMobileField</method>
</event_column_append>
</observers>
</adminhtml_block_html_before>
</events>
...
</adminhtml>
...
</config>
app/code/community/{Namespace}/{Module}/Model/Observer.php
<?php
class {Namespace}_{Module}_Model_Observer
{
public function addMobileField(Varien_Event_Observer $observer) {
$block = $observer->getEvent()->getBlock();
if (!isset($block)) {
return $this;
}
if ($block->getType() == 'adminhtml/system_account_edit_form') {
$form = $block->getForm();
$fieldset = $form->getElement('base_fieldset');
//add new website field
$fieldset->addField('mobile', 'text', array(
'name' => 'mobile',
'label' => Mage::helper('adminhtml')->__('Mobile No.'),
'title' => Mage::helper('adminhtml')->__('Mobile No.'),
'required' => false,
),
'email'
);
$userId = Mage::getSingleton('admin/session')->getUser()->getId();
$user = Mage::getModel('admin/user')
->load($userId);
$user->unsetData('password');
$form->setValues($user->getData());
}
}
}
And at last, you need to override Mage_Adminhtml_System_AccountController
controller file to save mobile field.
...
/**
* Saving edited user information
*/
public function saveAction()
{
...
$user->setId($userId)
->setUsername($this->getRequest()->getParam('username', false))
->setFirstname($this->getRequest()->getParam('firstname', false))
->setLastname($this->getRequest()->getParam('lastname', false))
->setEmail(strtolower($this->getRequest()->getParam('email', false)))
->setMobile($this->getRequest()->getParam('mobile', false));
...
}
...