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

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

2
  • Oh okay, a normal button if possible?
    – joe young
    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/… Aug 7, 2020 at 14:09

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.