I created my own admin route.
This is it's controller:
Route controller
<?php
class Mediabase extends \Magento\Sales\Controller\Adminhtml\Order
{
public function execute()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$urlInterface = $objectManager->get(\Magento\Backend\Model\UrlInterface::class);
$mediabaseUrl = $urlInterface->getUrl("uo_mediabase/order/mediabase");
print_r($this->getRequest()->getPost());
$currentUrl = $urlInterface->getCurrentUrl();
}
}
?>
This is the form which is calling the route
<div class="admin__page-section order-view-billing-shipping">
<div class="admin__page-section-title">
<span class="title">Mediabase</span>
</div>
<div class="admin__page-section-item-title">
<span class="title">Bestellnummer</span>
</div>
<div class="admin__page-section-item-content">
Mediabase-Bestellnummer: <?php echo $block->getMediabaseNumber(); ?>
</div>
<br/>
<form id="mediabase_edit_form" action="<?= $this->getFormUrl() ?>" method="post">
<input type="text" name="bestellnr"><br/>
<input class="action-default" type="submit" value="Speichern">
</form>
</div>
So when the route is called I want to get the
bestellnr
value.
However my form doesn't seem to send POST data.
Do you know how I can achieve that?
Thanks!
Best Answer
First check your controller is being called on form submit or not if it's being called then follow below method
If you want to get post data from controller, $post = $this->getRequest()->getPostValue();
Here your full code,
Also You have to declare storemanager object inside __construct() function of your php file instead of use dirctly objectmanager.
I have updated your code as below,
Also, you can check here:
http://clever-code.com/how-to-save-form-data-to-the-custom-table-in-magento-2/