0

I'm looking to add a button that executes my own custom code.

I've successfully created the page, along with a button but I can't for the life of me get it todo anything. I've stripped it back down to basics, where I just display the page with the layout form etc.

Please see my code below, I wondered if anyone would be able to help me/point me in the right direction.

Thank you in advance.

My Controller

 <?php
namespace Ozark\Maxoptra\Controller\Adminhtml\ExportEmail;
use Laminas\Form\Element\Button;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Magento\Framework\View\ResultPageFactory;
class Index extends \Magento\Backend\App\Action
{
 private $resultPageFactory;
 public function __construct(
 \Magento\Backend\App\Action\Context $context,
 \Magento\Framework\View\Result\PageFactory $resultPageFactory
 ) {
 parent::__construct($context);
 $this->resultPageFactory = $resultPageFactory;
 }
 public function execute()
 {
 $resultPage = $this->resultPageFactory->create(); // this crete an empty page
 return $resultPage;// this show page
 }
}

Template

 <h2 class="export main">Test [email protected]</h2>
<br>
<form class="export button">
 <input type="submit" value="Run Export" name="runExport" />
</form>
asked Aug 4, 2020 at 12:47
3
  • try check this link magento.stackexchange.com/a/317429/82670 Commented Aug 4, 2020 at 12:50
  • Great, thank you. But I'm only looking to have a singular button on the screen, when pressed executes code which sends a email containing order data. I've got it working as a console command, just can't figure out how to link a button. Commented Aug 4, 2020 at 12:58
  • in this link there are sample module. what you are looking for is in that module. drive.google.com/file/d/1UFMtTOkwbaPKbIdAZ_DDZKJkZHvpIoPW/view Commented Aug 4, 2020 at 13:14

1 Answer 1

0

in magento 2.x ui components are used for adding the classic orange buttons at the top (saving, modifying, deleting etc.). Are you interested in such a thing or a normal button?

Cheers

answered Aug 4, 2020 at 13:46
2
  • Oh okay, a normal button if possible? Commented Aug 7, 2020 at 11:16
  • yes but usually, on backend buttons are all created by ui component. Follow this guide for create a page within pthml file. When you got the phtml file you will be able to insert as many buttons as you prefer. magento.stackexchange.com/questions/194368/… Commented Aug 7, 2020 at 14:09

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.