2

my edit.php file in magento admin custom module

 $this->addButton(
            'approve',
            [
                'label' => __('Approve'),
                'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to Approve Quote?'))
                    . ','
                    . json_encode($this->getDeleteUrl()
                    )
                    . ')',
                'class' => 'scalable delete',
                'level' => -1
            ]
        );

here i want to add my custom method(Logic) how i can add

'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to Approve Quote?'))

when add any method shows error

Fatal error: Uncaught Error: Call to undefined function Webkul\Mpquotesystem\Block\Adminhtml\Managequotes\getDeleteUrl() in /var/www/html/equpo2/app/code/Webkul/Mpquotesystem/Block/Adminhtml/Managequotes/Edit.php on line 57

how i can solve this??

0

'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to Approve Quote?'))

Above code just display text message in popup. so you can not write logic in this line.

And you get fatal error because getDeleteUrl() is not exist.

If you want to add custom logic then you have to create controller for that. follow below step.

Create get URL function

 public function getDeleteUrl()
 {
    return $this->getUrl('*/*/delete', ['id' => $this->getId()]);
 }

Create controller in given path

app/code/Namespace/Modulename/Controller/Index/Delete.php

<?php
 namespace Namespace\Modulename\Controller\Adminhtml\Index;

 class Delete extends \Namespace\Modulename\Controller\Adminhtml\Index
 {
     public function execute()
     {
       //Write your custom logic
     }
 }

I hope it helps!

  • how i add the controller method 'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to Approve Quote?')) – prabhakaran7 Mar 14 at 13:37
  • when click the button record is deleting why?? – prabhakaran7 Mar 14 at 13:38
  • Replace your onclick code with this 'on_click' => 'deleteConfirm(\'' . __( 'Are you sure you want to do this?' ) . '\', \'' . $this->getDeleteUrl() . '\')' – Chirag Patel Mar 14 at 13:39
  • If you write delete record login in controller then it will be delete. – Chirag Patel Mar 14 at 13:40
  • how the block and controller will merge – prabhakaran7 Mar 14 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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