Add a button in fornt of each row that send email to the a column email value
-
05-10-2020 - |
题
I have a form in front end that save vale in database and shown in the admin grid. I have an action button in front of each row so click of this button i want to get the rest of columns value.
I have following grid in admin:
protected function _prepareColumns()
{
$this->addColumn('name', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Name'),
'align' => 'right',
'width' => '10px',
'index' => 'name',
));
$this->addColumn('email', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Email'),
'align' => 'left',
'index' => 'email',
'width' => '50px',
));
$this->addColumn('comment', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Comments'),
'width' => '150px',
'index' => 'comment',
));
$this->addColumn('action',
array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Send Email'),
'width' => '50',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('optfirst_reviewmycompany')->__('Review Email'),
'url' => array('base'=> '*/*/view'),
'field' => 'id'
)),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
How i can do this for each row.
解决方案
In your controller file in which the action for loading grid page is defined, add function mentioned below.
public function viewAction(){
$request=$this->getRequest()->getParams();
$modelData=Mage::getModel('optfirst_reviewmycompany/contacts')->load($request['id']);//This will fetch all data corresponding to a particular id.
$mail = Mage::getModel('core/email')
->setToName($senderName)
->setToEmail($customerEmail)
->setBody($html)
->setSubject('Subject :')
->setFromEmail($senderEmail)
->setFromName($senderName)
->setType('html');
try{
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Mail sent successfully');
}
catch(Exception $error)
{
Mage::getSingleton('core/session')->addError($error->getMessage());
return false;
}
$this->_redirect('*/*/');
}