Magento 2 | Get Post Params The Next CEO of Stack OverflowMagento 2: How to get Post data in backend/adminhtml?magento 2 get empty post array in version 2.0.5Magento 2: How to override newsletter Subscriber modelHow to treat POST data incoming to MagentoMagento Admin Strip of Post DataCustom routes with GET Params : HTTP RESPONSE 302 ; how to get GET params values?Magento 2.2.4 : post data in urlMagento 1.9: How do I know if my form is working? Handling post informationCreate REST API with post paramsMagento 2: Image not uploading in grid "Attention: File was not uploaded”
Is it ever safe to open a suspicious html file (e.g. email attachment)?
Why does standard notation not preserve intervals (visually)
How do I go from 300 unfinished/half written blog posts, to published posts?
Why does the UK parliament need a vote on the political declaration?
Why am I allowed to create multiple unique pointers from a single object?
Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?
Does it take more energy to get to Venus or to Mars?
A "random" question: usage of "random" as adjective in Spanish
What flight has the highest ratio of time difference to flight time?
"and that skill is always a class skill for you" - does "always" have any meaning in Pathfinder?
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
What's the best way to handle refactoring a big file?
Make solar eclipses exceedingly rare, but still have new moons
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
How to avoid supervisors with prejudiced views?
Why has the US not been more assertive in confronting Russia in recent years?
What does convergence in distribution "in the Gromov–Hausdorff" sense mean?
Unreliable Magic - Is it worth it?
FBX seems to be empty when imported into Blender
Why don't programming languages automatically manage the synchronous/asynchronous problem?
MessageLevel in QGIS3
What is ( CFMCC ) on ILS approach chart?
Preparing Indesign booklet with .psd graphics for print
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Magento 2 | Get Post Params
The Next CEO of Stack OverflowMagento 2: How to get Post data in backend/adminhtml?magento 2 get empty post array in version 2.0.5Magento 2: How to override newsletter Subscriber modelHow to treat POST data incoming to MagentoMagento Admin Strip of Post DataCustom routes with GET Params : HTTP RESPONSE 302 ; how to get GET params values?Magento 2.2.4 : post data in urlMagento 1.9: How do I know if my form is working? Handling post informationCreate REST API with post paramsMagento 2: Image not uploading in grid "Attention: File was not uploaded”
I created my own admin route.
This is it's controller:
Route controller
<?php
class Mediabase extends MagentoSalesControllerAdminhtmlOrder
public function execute()
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$urlInterface = $objectManager->get(MagentoBackendModelUrlInterface::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!
magento2 forms router post-data
add a comment |
I created my own admin route.
This is it's controller:
Route controller
<?php
class Mediabase extends MagentoSalesControllerAdminhtmlOrder
public function execute()
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$urlInterface = $objectManager->get(MagentoBackendModelUrlInterface::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!
magento2 forms router post-data
If you put exit on controller, does it work when click submit?
– Sukumar Gorai
Jul 16 '18 at 12:51
add a comment |
I created my own admin route.
This is it's controller:
Route controller
<?php
class Mediabase extends MagentoSalesControllerAdminhtmlOrder
public function execute()
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$urlInterface = $objectManager->get(MagentoBackendModelUrlInterface::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!
magento2 forms router post-data
I created my own admin route.
This is it's controller:
Route controller
<?php
class Mediabase extends MagentoSalesControllerAdminhtmlOrder
public function execute()
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$urlInterface = $objectManager->get(MagentoBackendModelUrlInterface::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!
magento2 forms router post-data
magento2 forms router post-data
edited 24 mins ago
k33n
asked Jul 16 '18 at 12:28
k33nk33n
455110
455110
If you put exit on controller, does it work when click submit?
– Sukumar Gorai
Jul 16 '18 at 12:51
add a comment |
If you put exit on controller, does it work when click submit?
– Sukumar Gorai
Jul 16 '18 at 12:51
If you put exit on controller, does it work when click submit?
– Sukumar Gorai
Jul 16 '18 at 12:51
If you put exit on controller, does it work when click submit?
– Sukumar Gorai
Jul 16 '18 at 12:51
add a comment |
2 Answers
2
active
oldest
votes
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,
class Index extends MagentoFrameworkAppActionAction
/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;
/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;
/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;
/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $storeManager
)
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
$this->storeManager = $storeManager;
/**
* Flush cache storage
*
*/
public function execute()
$currentStore = $this->storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();
$post = $this->getRequest()->getPostValue();
echo "<pre>";
print_r($post);
exit;
Also, you can check here:
http://clever-code.com/how-to-save-form-data-to-the-custom-table-in-magento-2/
add a comment |
You can use the following code to get post or get values from form to controller action:
Below code will return all the parameters either post or get:
$params = $this->getRequest()->getParams();
If you want only one variable value then you can use the following code:
$variable_name = $this->getRequest()->getParam('variable_name');
In your case you can use the following code to get bestellnr value:
$bestellnr = $this->getRequest()->getParam('bestellnr');
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f234684%2fmagento-2-get-post-params%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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,
class Index extends MagentoFrameworkAppActionAction
/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;
/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;
/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;
/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $storeManager
)
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
$this->storeManager = $storeManager;
/**
* Flush cache storage
*
*/
public function execute()
$currentStore = $this->storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();
$post = $this->getRequest()->getPostValue();
echo "<pre>";
print_r($post);
exit;
Also, you can check here:
http://clever-code.com/how-to-save-form-data-to-the-custom-table-in-magento-2/
add a comment |
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,
class Index extends MagentoFrameworkAppActionAction
/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;
/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;
/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;
/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $storeManager
)
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
$this->storeManager = $storeManager;
/**
* Flush cache storage
*
*/
public function execute()
$currentStore = $this->storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();
$post = $this->getRequest()->getPostValue();
echo "<pre>";
print_r($post);
exit;
Also, you can check here:
http://clever-code.com/how-to-save-form-data-to-the-custom-table-in-magento-2/
add a comment |
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,
class Index extends MagentoFrameworkAppActionAction
/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;
/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;
/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;
/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $storeManager
)
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
$this->storeManager = $storeManager;
/**
* Flush cache storage
*
*/
public function execute()
$currentStore = $this->storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();
$post = $this->getRequest()->getPostValue();
echo "<pre>";
print_r($post);
exit;
Also, you can check here:
http://clever-code.com/how-to-save-form-data-to-the-custom-table-in-magento-2/
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,
class Index extends MagentoFrameworkAppActionAction
/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;
/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;
/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;
/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $storeManager
)
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
$this->storeManager = $storeManager;
/**
* Flush cache storage
*
*/
public function execute()
$currentStore = $this->storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();
$post = $this->getRequest()->getPostValue();
echo "<pre>";
print_r($post);
exit;
Also, you can check here:
http://clever-code.com/how-to-save-form-data-to-the-custom-table-in-magento-2/
edited Mar 4 at 10:30
Ashish Viradiya
1,0531830
1,0531830
answered Jul 16 '18 at 12:32
jackjack
476722
476722
add a comment |
add a comment |
You can use the following code to get post or get values from form to controller action:
Below code will return all the parameters either post or get:
$params = $this->getRequest()->getParams();
If you want only one variable value then you can use the following code:
$variable_name = $this->getRequest()->getParam('variable_name');
In your case you can use the following code to get bestellnr value:
$bestellnr = $this->getRequest()->getParam('bestellnr');
add a comment |
You can use the following code to get post or get values from form to controller action:
Below code will return all the parameters either post or get:
$params = $this->getRequest()->getParams();
If you want only one variable value then you can use the following code:
$variable_name = $this->getRequest()->getParam('variable_name');
In your case you can use the following code to get bestellnr value:
$bestellnr = $this->getRequest()->getParam('bestellnr');
add a comment |
You can use the following code to get post or get values from form to controller action:
Below code will return all the parameters either post or get:
$params = $this->getRequest()->getParams();
If you want only one variable value then you can use the following code:
$variable_name = $this->getRequest()->getParam('variable_name');
In your case you can use the following code to get bestellnr value:
$bestellnr = $this->getRequest()->getParam('bestellnr');
You can use the following code to get post or get values from form to controller action:
Below code will return all the parameters either post or get:
$params = $this->getRequest()->getParams();
If you want only one variable value then you can use the following code:
$variable_name = $this->getRequest()->getParam('variable_name');
In your case you can use the following code to get bestellnr value:
$bestellnr = $this->getRequest()->getParam('bestellnr');
answered Jul 16 '18 at 12:54
Sukumar GoraiSukumar Gorai
6,9303729
6,9303729
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f234684%2fmagento-2-get-post-params%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you put exit on controller, does it work when click submit?
– Sukumar Gorai
Jul 16 '18 at 12:51