Question

How can i new field in admin filed that contain mailto functionality

$fieldset->addField('email', 'link', array(
    'label'     => Mage::helper('mumodule')->__('Email'),
    "target"=>"_blank",
    'mailto' => Mage::registry('mumodule')->getData('email'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    ));

using this way i cant add functionality.

is it possible to add new filed with mailto functionality?

Was it helpful?

Solution 2

i achieve in simple way

$fieldset->addField('email', 'link', array(
        'label'     => Mage::helper('mumodule')->__('Email'),
        'target'    => '_blank',
        'href'      => 'mailto:' . urlencode(Mage::registry('mumodule')->getData('email')),
        'class'     => 'required-entry',
    ));

mailto: is part of the URL so it should be assigned in the href attribute:

OTHER TIPS

You must create your own form field renderer. For this you will need a custom module. If you don't know how to do that here's a good starting point: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_create_an_admin_form_module

Create a new file in app/code/[local/community]/MyCompany/MyModule/Varien/Data/Form/Element/Mailto.php with this content:

class MyCompany_MyModule_Varien_Data_Form_Element_Mailto extends Varien_Data_Form_Element_Abstract {
public function __construct($data) {
    parent::__construct($data);
    $this->setType('link');
}

public function getElementHtml() {
    $html = $this->getBeforeElementHtml();
    if ($this->getValue()) {
        $html .= '<a href="mailto:'.$this->getValue().'"></a> ';
    }
    $html .= $this->getAfterElementHtml();
    return $html;
}

After that go to your form file and add this to the fieldset:

$fieldset->addType('mailto','MyCompany_MyModule_Varien_Data_Form_Element_Mailto');

$fieldset->addField('email', 'mailto', array(
    'label'     => Mage::helper('mymodule')->__('Email'),
    'name'      => 'email',
));

Of course, you should replace MyCompany namespace with the namespace that you already use in the module and MyModule with your module name. Also don't forget to place the file in the code pool where your module already exists: local/community

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top