The saveAction()
method (or the method you send the for to, if it's an other one) should look like this:
public function saveAction(){
if ($data = $this->getRequest()->getPost()) {
//init model and set data
$model = Mage::getModel('example/example');
if ($id = $this->getRequest()->getParam('id')) {//the parameter name may be different
$model->load($id);
}
$model->addData($data);
try{
//try to save it
$model->save();
Mage::getSingleton('adminhtml/session')->addSuccess('Saved');
//redirect to grid.
$this->_redirect('*/*/');
}
catch (Exception $e){
//if there is an error return to edit
Mage::getSingleton('adminhtml/session')->addError('Not Saved. Error:'.$e->getMessage());
Mage::getSingleton('adminhtml/session')->setExampleFormData($data);
$this->_redirect('*/*/edit', array('id'=>$mode->getId(), '_current'=>true));
}
}
}
Something like this may help you
$base_fieldset->addField(
'your_btn', 'button', array(
'name' => 'your_btn',
'label' => Mage::helper('testmodule')->__(
'Click on folowing link to test popup Dialog:'
),
'value' => $this->helper('testmodule')->__('Test popup dialog >>'),
'class' => 'form-button',
'onclick' => 'javascript:openMyPopup()'
)
);
$form->setUseContainer(true);
$this->setForm($form);
parent::_prepareForm();
Then in layout file
<?php echo $this->getFormInitScripts() ?>
<script type="text/javascript">
function openMyPopup() {
var url = '<?php echo $this->getUrl('adminhtml/dashboard/index') ?>?';
if ($('browser_window') && typeof(Windows) != 'undefined') {
Windows.focus('browser_window');
return;
}
var dialogWindow = Dialog.info(null, {
closable:true,
resizable:false,
draggable:true,
className:'magento',
windowClassName:'popup-window',
title:'Test popup Dialog',
top:50,
width:300,
height:150,
zIndex:1000,
recenterAuto:false,
hideEffect:Element.hide,
showEffect:Element.show,
id:'browser_window',
url:url,
onClose:function (param, el) {
alert('onClose');
}
});
}
function closePopup() {
Windows.close('browser_window');
}
</script>
Best Answer
You will have to add that event yourself to your controller, to check what button is clicked you can do the following:
In your block widget definition for your edit form you need to configure your save and continue url for the button:
And in the saveAction function you can then check if the parameter back is used:
You also need to set
In the event observer you can check the clicked button, when rediredit is false the save button is clicked, else the save and continue edit button is clicked.