How to get post data variables after submition a form in magento

前端 未结 5 1388
暖寄归人
暖寄归人 2021-01-31 20:39

How do I get data of post variables ? Like if I post form with post method then I can get itt with $_REQUEST or with $_POST. How I can do this in mgento ?

5条回答
  •  逝去的感伤
    2021-01-31 21:11

    You can read the values with

    $this->getRequest()->getParam('field_name');
    

    The code above will get you values from GET and POST. But if you want to check if something was sent specifically through POST you can get it like this.

    $this->getRequest()->getPost('field_name');
    

    You can even specify a default value.

    $somevar = $this->getRequest()->getParam('some_var', 7);
    

    this means that if $_POST['some_var'] is not set, the variable $somevar will have the value 7.

提交回复
热议问题