Hey I'm beginner at Magento 2, and i don't know to much about UI component...
I'm creating a register form, and i want to pass Data of a UI Component Form to a Controller.
So i have a Form and i got a Button that i want to use it to get value from a dropdown field(combobox) of the Form.
I made the Block and the Controller, ok, the Block is calling the Controller right. But i don't know how to pass a specific value of the form to the controller. How can i do this?
I tried to use this command: $this->getRequest()->getParams(); but only returns ID and KEY.
And when i tried this command: $this->getRequest()->getPostValue(); it just returns an empty array...
Any help is appreciated !
DeleteHeader.php (Controller):
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$id = $this->getRequest()->getParam('id');
$this->save->getCombo();
$txt = 'DELETE HEADER : ' . $id;
$this->logger->log('DEBUG', $txt);
return $resultRedirect->setPath('api/data/edit/id/' . $id);
}
DeleteHeader Block (Button):
public function getButtonData()
{
$url = $this->getUrl("api/data/deleteheader", ['id' => $this->getDataId()]);
return [
'label' => __('Delete Header'),
'class' => 'custom-button-class',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'deleteheader'],
],
],
'on_click' => "confirmSetLocation(' Certeza ? ','" . $url . " ')",
'sort_order' => 80,
];
}
-
did you eventually succeed? thanks for letting us your feedback RafaelHerve Tribouilloy– Herve Tribouilloy2020年07月01日 08:27:15 +00:00Commented Jul 1, 2020 at 8:27
-
Did you solve the issue? I have exactly the same behavior, params have only id and form_key without any other data from fields.Duddy Woody– Duddy Woody2024年02月24日 17:38:14 +00:00Commented Feb 24, 2024 at 17:38
2 Answers 2
$getParams = $this->getRequest()->getParam('myparam');
this is fine to use a get params. However your controller has to be a get controller class MyAction extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface if you want to use get parameters.
I wrote a repository for you to take a look: https://bitbucket.org/magstaging/controllerwithjavascript/src/master/
-
Your repository is related to the frontend, It's strange(probably for me), but in frontend, I used something like request->getContent() instead of params or post value. It's not working for backend - getParams() or getPostValue() have id+form_key and empty respectively, getContent is empty as well.Duddy Woody– Duddy Woody2024年02月24日 17:43:16 +00:00Commented Feb 24, 2024 at 17:43
Use This in Your Controller File...
$post = $this->getRequest()->getPost();
Then You Can Use Form value using $post['your_field_name']
-
I tried this, it returns an empty array.Rafael Fagundes– Rafael Fagundes2020年06月26日 12:16:55 +00:00Commented Jun 26, 2020 at 12:16
-
plz share your code of controller fileMark Philips– Mark Philips2020年06月26日 12:29:55 +00:00Commented Jun 26, 2020 at 12:29
-
I updated, using this code, the only params that i can get are ID and KeyRafael Fagundes– Rafael Fagundes2020年06月26日 12:54:59 +00:00Commented Jun 26, 2020 at 12:54
Explore related questions
See similar questions with these tags.