0

Greets. {{Solved}} In order to get POST data you MUST use $this->formHidden in order to hold all the data. Even though variables are inside the they don't get passed if they aren't in some sort of form item.

I am unable to access post data in ZEND.

Path of User - START INDEX PAGE ->Submit Page ->Pay Page

I created a controller, extended the Zend Controller, and added an action called payAction. The user can go from the Index Page to the Submit Page. After I have all their data inside variables, I used a form and a submit button to go to the "pay page". However, I cannot get any of the POST data.

public function payAction() { $data = $this->getRequest(); } 

I have tried putting getRequest, getParam, getRawBody inside that controller function. In the page itself I have tried.

echo 'Hello'; echo $request; echo $data; echo $_POST['payZip']; echo $_POST['data']; echo $_POST[$data]; echo $request; echo $this->values['payZip']; echo $payZip; echo $this->values['shippingDone']; echo $stuff; 

Is there ANYTHING I can place in my controller or in my view in order to get my post data? I used a form method="post" and a button and it DOES allow me to get to the page. I can see Hello. But NONE of the post data is available.

Any assistance would be appreciated.

Thank you.

-- Update

 $data = $this->getRequest(); $param = $this->_request->getParam('payZip'); if($this->getRequest()->isPost()) { print_r($this->_getAllParams()); echo $param; } 

Doing that gives me - HelloArray ( [controller] => wheel [action] => pay [module] => default [shipping] => UPS Ground [payPal] => Secure Payment System )

But I still can't print payZip... I did echo and nothing comes out.

1
  • I updated my answer to, as I noticed how you where echoing stuff out. See my "EDIT" section below. I will add a little more detail to my answer for better explanation. Commented Aug 9, 2012 at 20:34

1 Answer 1

1

To get parameters from Zend Framework you need to do this in the Action Controller:

$data = $this->_request->getParams(); 

You can also get individual params like this

$param = $this->_request->getParam('payZip'); 

What it appears your doing wrong is you're only getting the "request object". You need to then call that objects method to get the request data.

Here's some simple code I often use when testing parameters:

public function indexAction() { #::DEBUG:: echo '<pre>'; print_r($this->_request->getParams()); echo '</pre>'; #::DEBUG:: } 

This will show all your parameters. What you will notice is that you will also get the names of the Module, Controller and Action with your params.

EDIT

Ps. If you're trying to use the parameter in the view script you need to do this:

echo $this->data['payZip']; echo $this->param; 

In your Action Controller, you save your data to the "view" object by doing this:

$this->view->myVariable = 'Hello'; 

But when you're in a view script, you are IN the view script, so $this represents $this->view from the action controller.

So, you access the variable like this:

echo $this->myVariable; 

Wrapping everything into a bigger code chunk for understanding:

Your Controller

public function indexAction() { // get all parameters and pass them to the view $this->view->params = $this->_request->getParams(); // get an individual parameter and pass it to the view $this->view->payZip = $this->_request->getParam('payZip'); } 

Your View Script

<!-- Dump all parameters --> <pre><?php print_r($this->params); ?></pre> <!-- Print payZip --> <p>My PayZip is: <?php echo $this->payZip; ?></p> <!-- Print payZip from full parameter array --> <p>My PayZip (array) is: <?php echo $this->data['payZip']; ?></p> 

I hope that helps!

Sign up to request clarification or add additional context in comments.

2 Comments

I used your debug function and it prints [controller] => wheel [action] => pay [module] => default [shipping] => UPS Ground [payPal] => Secure Payment System
I got it figured out. Thank you so much. Each variable HAS to be in the form of a $this->formHidden for it to show up. I will update my question to reflect this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.