Magento 2 - Unable to Get Request Params in controller The 2019 Stack Overflow Developer Survey Results Are InRemove or manipulate parameters in controllerAdding request params to observer redirectOverwriting controller vs overwriting action controller requestMagento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCan't get my ajax request to call controllerMagento 2 - Send processed data from Controller to PHTMLMagento 2 - Send form data to Controller using AJAX and return Result to PHTMLHow to send parameter to controllerGetting raw request body in controllercall a controller in other module

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Old scifi movie from the 50s or 60s with men in solid red uniforms who interrogate a spy from the past

Why is the maximum length of OpenWrt’s root password 8 characters?

Can there be female White Walkers?

Is it okay to consider publishing in my first year of PhD?

Why doesn't shell automatically fix "useless use of cat"?

Are there any other methods to apply to solving simultaneous equations?

Can an undergraduate be advised by a professor who is very far away?

Can withdrawing asylum be illegal?

Why can't devices on different VLANs, but on the same subnet, communicate?

Dropping list elements from nested list after evaluation

Why doesn't UInt have a toDouble()?

How to type this arrow in math mode?

How to add class in ko template in magento2

Short story: man watches girlfriend's spaceship entering a 'black hole' (?) forever

Is there a way to generate a uniformly distributed point on a sphere from a fixed amount of random real numbers?

What information about me do stores get via my credit card?

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

How to charge AirPods to keep battery healthy?

Loose spokes after only a few rides

Output the Arecibo Message

Getting crown tickets for Statue of Liberty

Why are there uneven bright areas in this photo of black hole?

Match Roman Numerals



Magento 2 - Unable to Get Request Params in controller



The 2019 Stack Overflow Developer Survey Results Are InRemove or manipulate parameters in controllerAdding request params to observer redirectOverwriting controller vs overwriting action controller requestMagento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCan't get my ajax request to call controllerMagento 2 - Send processed data from Controller to PHTMLMagento 2 - Send form data to Controller using AJAX and return Result to PHTMLHow to send parameter to controllerGetting raw request body in controllercall a controller in other module



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I am trying to get input data in the controller but controller not getting url params.



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction


/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

protected $resultJsonFactory;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)


$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);



public function execute()

var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();

$block = $resultPage->getLayout()
->createBlock('CrudCrudatfrontendBlockIndex')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();

$result->setData($block);
return $result;




Here is my phtml file



<div class="row clearfix">
<div class="col-md-12 column">

<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>


<script>
require(['jquery'],function()
jQuery(document).ready(function()
alert("hi")
jQuery("#form_height").submit(function()

var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();

var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax(
url: url,
type: "POST",
data: height:heightValue,weight:weightValue,
//data: jQuery(this).serialize(),
success: function(response)
// alert(heightValue);
console.log(response.output);
window.location.href = url;

);

return false;
);
);
);
</script>


I am getting values in console.










share|improve this question






















  • you better use MagentoFrameworkAppRequestHttp

    – magefms
    10 mins ago

















2















I am trying to get input data in the controller but controller not getting url params.



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction


/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

protected $resultJsonFactory;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)


$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);



public function execute()

var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();

$block = $resultPage->getLayout()
->createBlock('CrudCrudatfrontendBlockIndex')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();

$result->setData($block);
return $result;




Here is my phtml file



<div class="row clearfix">
<div class="col-md-12 column">

<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>


<script>
require(['jquery'],function()
jQuery(document).ready(function()
alert("hi")
jQuery("#form_height").submit(function()

var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();

var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax(
url: url,
type: "POST",
data: height:heightValue,weight:weightValue,
//data: jQuery(this).serialize(),
success: function(response)
// alert(heightValue);
console.log(response.output);
window.location.href = url;

);

return false;
);
);
);
</script>


I am getting values in console.










share|improve this question






















  • you better use MagentoFrameworkAppRequestHttp

    – magefms
    10 mins ago













2












2








2








I am trying to get input data in the controller but controller not getting url params.



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction


/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

protected $resultJsonFactory;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)


$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);



public function execute()

var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();

$block = $resultPage->getLayout()
->createBlock('CrudCrudatfrontendBlockIndex')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();

$result->setData($block);
return $result;




Here is my phtml file



<div class="row clearfix">
<div class="col-md-12 column">

<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>


<script>
require(['jquery'],function()
jQuery(document).ready(function()
alert("hi")
jQuery("#form_height").submit(function()

var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();

var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax(
url: url,
type: "POST",
data: height:heightValue,weight:weightValue,
//data: jQuery(this).serialize(),
success: function(response)
// alert(heightValue);
console.log(response.output);
window.location.href = url;

);

return false;
);
);
);
</script>


I am getting values in console.










share|improve this question














I am trying to get input data in the controller but controller not getting url params.



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction


/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

protected $resultJsonFactory;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)


$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);



public function execute()

var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();

$block = $resultPage->getLayout()
->createBlock('CrudCrudatfrontendBlockIndex')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();

$result->setData($block);
return $result;




Here is my phtml file



<div class="row clearfix">
<div class="col-md-12 column">

<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>


<script>
require(['jquery'],function()
jQuery(document).ready(function()
alert("hi")
jQuery("#form_height").submit(function()

var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();

var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax(
url: url,
type: "POST",
data: height:heightValue,weight:weightValue,
//data: jQuery(this).serialize(),
success: function(response)
// alert(heightValue);
console.log(response.output);
window.location.href = url;

);

return false;
);
);
);
</script>


I am getting values in console.







controllers magento-2.1.7 parameter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 18 mins ago









Bhakti ThakkarBhakti Thakkar

584114




584114












  • you better use MagentoFrameworkAppRequestHttp

    – magefms
    10 mins ago

















  • you better use MagentoFrameworkAppRequestHttp

    – magefms
    10 mins ago
















you better use MagentoFrameworkAppRequestHttp

– magefms
10 mins ago





you better use MagentoFrameworkAppRequestHttp

– magefms
10 mins ago










2 Answers
2






active

oldest

votes


















0














Try this using MagentoFrameworkAppRequestHttp



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction
MagentoFrameworkControllerResultJson




share






























    0














    Try this,



     require(['jquery'],function()
    jQuery(document).ready(function()
    alert("hi")
    jQuery('#calculateTotalSubmit').on('click', function()

    var heightValue = jQuery("input[name='height']").val();
    var weightValue = jQuery("input[name='weight']").val();

    var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
    jQuery.ajax(
    url: url,
    type: "POST",
    data: height:heightValue,weight:weightValue,
    //data: jQuery(this).serialize(),
    success: function(response)
    // alert(heightValue);
    console.log(response.output);
    window.location.href = url;

    );

    return false;
    );
    );
    );


    and your form post action should be like action="#"



    Hope this helps





    share























      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
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269810%2fmagento-2-unable-to-get-request-params-in-controller%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









      0














      Try this using MagentoFrameworkAppRequestHttp



      <?php

      namespace CrudCrudatfrontendControllerResult;

      use MagentoFrameworkAppActionContext;
      use MagentoFrameworkViewResultPageFactory;
      use MagentoFrameworkControllerResultJsonFactory;

      class Result extends MagentoFrameworkAppActionAction
      MagentoFrameworkControllerResultJson




      share



























        0














        Try this using MagentoFrameworkAppRequestHttp



        <?php

        namespace CrudCrudatfrontendControllerResult;

        use MagentoFrameworkAppActionContext;
        use MagentoFrameworkViewResultPageFactory;
        use MagentoFrameworkControllerResultJsonFactory;

        class Result extends MagentoFrameworkAppActionAction
        MagentoFrameworkControllerResultJson




        share

























          0












          0








          0







          Try this using MagentoFrameworkAppRequestHttp



          <?php

          namespace CrudCrudatfrontendControllerResult;

          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkViewResultPageFactory;
          use MagentoFrameworkControllerResultJsonFactory;

          class Result extends MagentoFrameworkAppActionAction
          MagentoFrameworkControllerResultJson




          share













          Try this using MagentoFrameworkAppRequestHttp



          <?php

          namespace CrudCrudatfrontendControllerResult;

          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkViewResultPageFactory;
          use MagentoFrameworkControllerResultJsonFactory;

          class Result extends MagentoFrameworkAppActionAction
          MagentoFrameworkControllerResultJson





          share











          share


          share










          answered 5 mins ago









          magefmsmagefms

          2,6352528




          2,6352528























              0














              Try this,



               require(['jquery'],function()
              jQuery(document).ready(function()
              alert("hi")
              jQuery('#calculateTotalSubmit').on('click', function()

              var heightValue = jQuery("input[name='height']").val();
              var weightValue = jQuery("input[name='weight']").val();

              var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
              jQuery.ajax(
              url: url,
              type: "POST",
              data: height:heightValue,weight:weightValue,
              //data: jQuery(this).serialize(),
              success: function(response)
              // alert(heightValue);
              console.log(response.output);
              window.location.href = url;

              );

              return false;
              );
              );
              );


              and your form post action should be like action="#"



              Hope this helps





              share



























                0














                Try this,



                 require(['jquery'],function()
                jQuery(document).ready(function()
                alert("hi")
                jQuery('#calculateTotalSubmit').on('click', function()

                var heightValue = jQuery("input[name='height']").val();
                var weightValue = jQuery("input[name='weight']").val();

                var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
                jQuery.ajax(
                url: url,
                type: "POST",
                data: height:heightValue,weight:weightValue,
                //data: jQuery(this).serialize(),
                success: function(response)
                // alert(heightValue);
                console.log(response.output);
                window.location.href = url;

                );

                return false;
                );
                );
                );


                and your form post action should be like action="#"



                Hope this helps





                share

























                  0












                  0








                  0







                  Try this,



                   require(['jquery'],function()
                  jQuery(document).ready(function()
                  alert("hi")
                  jQuery('#calculateTotalSubmit').on('click', function()

                  var heightValue = jQuery("input[name='height']").val();
                  var weightValue = jQuery("input[name='weight']").val();

                  var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
                  jQuery.ajax(
                  url: url,
                  type: "POST",
                  data: height:heightValue,weight:weightValue,
                  //data: jQuery(this).serialize(),
                  success: function(response)
                  // alert(heightValue);
                  console.log(response.output);
                  window.location.href = url;

                  );

                  return false;
                  );
                  );
                  );


                  and your form post action should be like action="#"



                  Hope this helps





                  share













                  Try this,



                   require(['jquery'],function()
                  jQuery(document).ready(function()
                  alert("hi")
                  jQuery('#calculateTotalSubmit').on('click', function()

                  var heightValue = jQuery("input[name='height']").val();
                  var weightValue = jQuery("input[name='weight']").val();

                  var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
                  jQuery.ajax(
                  url: url,
                  type: "POST",
                  data: height:heightValue,weight:weightValue,
                  //data: jQuery(this).serialize(),
                  success: function(response)
                  // alert(heightValue);
                  console.log(response.output);
                  window.location.href = url;

                  );

                  return false;
                  );
                  );
                  );


                  and your form post action should be like action="#"



                  Hope this helps






                  share











                  share


                  share










                  answered 1 min ago









                  Prathap GunasekaranPrathap Gunasekaran

                  1,7831618




                  1,7831618



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269810%2fmagento-2-unable-to-get-request-params-in-controller%23new-answer', 'question_page');

                      );

                      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







                      Popular posts from this blog

                      Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                      Magento 2 disable Secret Key on URL's from terminal The Next CEO of Stack OverflowMagento 2 Shortcut/GUI tool to perform commandline tasks for windowsIn menu add configuration linkMagento oAuth : Generating access token and access secretMagento 2 security key issue in Third-Party API redirect URIPublic actions in admin controllersHow to Disable Cache in Custom WidgetURL Key not changing in Magento 2Product URL Key gets deleted when importing custom options - Magento 2Problem with reindex terminalMagento 2 - bin/magento Commands not working in Cpanel Terminal

                      Aasi (pallopeli) Navigointivalikko