2

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,
    ];
}
2
  • did you eventually succeed? thanks for letting us your feedback Rafael 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. Feb 24 at 17:38

2 Answers 2

0
$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/

1
  • 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. Feb 24 at 17:43
0

Use This in Your Controller File...

$post = $this->getRequest()->getPost();

Then You Can Use Form value using $post['your_field_name']

3
  • I tried this, it returns an empty array. Jun 26, 2020 at 12:16
  • plz share your code of controller file Jun 26, 2020 at 12:29
  • I updated, using this code, the only params that i can get are ID and Key Jun 26, 2020 at 12:54

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.