I have a custom form in Magento admin. When I submit the form with multiple click of the save button the multiple entry are inserted in my table, even if I have a form key.

if ($data = $this->getRequest()->getPost()) {       
    $request = $this->getRequest();
    $formKey = Mage::getSingleton('core/session')->getFormKey();             
    $request->setParam('form_key', $formKey);   
    $model = Mage::getModel('flpackage/packages');
    $id = $this->getRequest()->getParam('id');
    $oldPrice = '';
    if ($id) {
        $oldPrice = $model->getData('package_price');                                                
    try {
    } catch (Exception $e) {
        if($this->getRequest()->getParam('id')) {
            $this->_redirect('*/*/edit', array('id' => $id));
        } else {
        return ;
    if($id) {

Screen: enter image description here

Kindly suggest your answer for solving this issue.

3 Answers 3


You can create a function in one of your javascript files like this:

function savePackage(){
    if (editForm.submit() == false){
    varienGlobalEvents.attachEventHandler('formValidateAjaxComplete', function (){

Then, in your Edit.php block for your entity add this line in the _prepareLayout method:

$this->_updateButton('save', 'onclick', 'savePackage()');

This is not a hack or something I came up with.
This is how it works for saving the product attributes in the core:

  • This is the cleanest answer because it does not override core functionality. Commented Dec 4, 2015 at 13:10

Package Name has to be unique? If so, you could check before save, if item with the same name already exists:

$packageName = $this->getRequest()->getParam('package_name');
if ($model->load($packageName, 'package_name')->getId()) {
  • This is only work for the particular module. due you have any other idea to avoid inserting the multiple entry when click the save button multiple time
    – senthil
    Commented Dec 3, 2015 at 5:37
  • i check with existing customer and newsletter module in magento admin panel.but the customer multitime form submit is working fine(i mean even i click the save button multitime the single entry only inserting) but the newsletter if i click the save button for creating template means the template are inserting multiple time.
    – senthil
    Commented Dec 3, 2015 at 5:42

Well that was interesting bug in core Magento. Just do one line change this way.

  1. Open file /js/mage/adminhtml/form.js
  2. Add below one line code just before form is submit.

            /*Multiple Entry Bug Fix Start*/
            document.getElementsByClassName("save")[0].disabled = true;
            /*Multiple Entry Bug Fix End*/

    Approx line 67 (Just after admin form validation success)

This will fix all multiple entry bug in all Magento modules.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.