1

How do I get data of post variables ? Like if I post form with post method then I can get it with $_POST or not

this is my form

<form id="orderapproval-item-form" class="orderapproval-hidden" action="<?php echo $this->getDeclineUrl(); ?>" method="post">
    <input type="text" name="message" class="orderapproval-disabled" value="<?php echo $this->__('Enter decline reason'); ?>" id="decline" />
    <input type="submit" value="<?php echo $this->__('Decline'); ?>" onclick="namet()" />
  </form>

in phtml file i have added a form with post method i want to data variable of this form

I am using code this on same page

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

but i am not getting data

3
  • that's the way you should get it, unless you have an error somewhere. Maybe you send the form via GET. Maybe your field have a prefix and the name of the input looks like prefix['field_name'] ?
    – Marius
    Dec 13, 2016 at 10:16
  • @Marius where should i write this code on same page or controller... i am passing form via post i am not getting about get Dec 13, 2016 at 10:19
  • You need this in the controller that handles your request.
    – Marius
    Dec 13, 2016 at 10:20

3 Answers 3

1

You can get this by :

Mage::app()->getRequest()->getParam('field_name');
8
  • i am using above code but its not working for me ...i am working it on same phtml file am i right Dec 13, 2016 at 10:28
  • Your form action is on same page?....You also try to make a controller and send request there. Dec 13, 2016 at 10:31
  • this is my form <form id="orderapproval-item-form" class="orderapproval-hidden" action="<?php echo $this->getDeclineUrl(); ?>" method="post"> <input type="text" name="message" class="orderapproval-disabled" value="<?php echo $this->__('Enter decline reason'); ?>" id="decline" /> <input type="submit" value="<?php echo $this->__('Decline'); ?>" onclick="namet()" /> </form> Dec 13, 2016 at 10:33
  • i have action on same page Dec 13, 2016 at 10:33
  • how to make controller and send request there Dec 13, 2016 at 10:33
1

You can check what you getting in post by

$postData = $this->getRequest()->getPost();
echo '<pre>';
print_r($postData);

and then you can get the field value by key of that array like

$postData['key'];
6
  • this is my form code Dec 13, 2016 at 10:32
  • <form id="orderapproval-item-form" class="orderapproval-hidden" action="<?php echo $this->getDeclineUrl(); ?>" method="post"> <input type="text" name="message" class="orderapproval-disabled" value="<?php echo $this->__('Enter decline reason'); ?>" id="decline" /> <input type="submit" value="<?php echo $this->__('Decline'); ?>" onclick="namet()" /> </form> Dec 13, 2016 at 10:32
  • what are you gettting from <?php echo $this->getDeclineUrl(); ?> ?
    – Piyush
    Dec 13, 2016 at 10:38
  • this is same page url Dec 13, 2016 at 11:10
  • i am getting textbox value on same page but i want to call it on shopping cart page Dec 13, 2016 at 11:24
1

Use for phtml

Mage::app()->getRequest()->getPost('field_name');

in your case

Mage::app()->getRequest()->getPost('message');
3
  • i am using this Dec 13, 2016 at 10:40
  • form action on same page Dec 13, 2016 at 10:40
  • No problem with when you post then use it like if(Mage::app()->getRequest()->getPost('message')): echo Mage::app()->getRequest()->getPost('message'); endif; Dec 13, 2016 at 10:42

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.