I'm trying to save a simple phtml form with a single input field. Can't figure why clicking on 'Save' Button won't trigger a call to the save.php controller. Path seems ok, but no action is triggered. Code below:
Yotpo\Yotpo\Block\Adminhtml\System\index.php:
namespace Yotpo\Yotpo\Block\Adminhtml\System;
class Index extends \Magento\Backend\Block\Widget\Form\Container {
protected $_blockGroup = 'Yotpo_Yotpo';
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry,
\Yotpo\Yotpo\Block\Config $config,
array $data = []
) {
$this->_config = $config;
parent::__construct($context, $data);
}
protected function _construct()
{
$this->_blockGroup = 'Yotpo_Yotpo';
$this->_controller = 'adminhtml_Settings_index';
parent::_construct();
}
protected function _prepareLayout()
{
$this->getToolbar()->addChild(
'save_button',
'Magento\Backend\Block\Widget\Button',
[
'id' => 'save',
'label' => __('Save Configuration'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'save', 'target' => '#yotpo-form'],
]
]
]
);
}
public function getFormActionUrl()
{
return $this->getUrl('adminhtml/settings/save');
}
}
Yotpo\Yotpo\Controller\Adminhtml\Settings\save.php:
namespace Yotpo\Yotpo\Controller\Adminhtml\System;
class SaveRates extends \Magento\Backend\App\Action
{
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Yotpo\Yotpo\Block\Config $config,
array $data = []
) {
$this->_config = $config;
parent::__construct($context, $data);
}
public function execute()
{
$this->_redirect('adminhtml/*/');
}
}
Yotpo\Yotpo\View\Adminhtml\Layout\adminhtml_settings_index.xml:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="formkey" />
<body>
<referenceContainer name="content">
<block class="Yotpo\Yotpo\Block\Adminhtml\System\index" name="yotpo.settings" template="grid.phtml"/>
</referenceContainer>
</body>
</page>
Yotpo\Yotpo\View\Adminhtml\Templates\grid.phtml:
?>
<?php
/**
* @var $block \Yotpo\Yoypo\Block\Adminhtml\System\index
*/
?>
<form id="yotpo-form" action="<?php echo $block->getFormActionUrl() ?>" method="post">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="form_key" value="<?php echo $this->getFormKey(); ?>" />
<input id="app_key" type="text" value="<?php echo $block->_config->getAppKey();?>" class="
</form>
clicking on 'Save Configuration' button suppose to trigger the save action. if I add a simple html submit button - this button triggers the desired save action:
<input type="submit" value="submit">
How can I make the Magento save button to work?
Would appreciate your help!