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??

asked Mar 14, 2019 at 13:09

1 Answer 1

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!

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.