开发者

Zend controller/view newbie puzzle: $_GET & $_POST empty - on receipt from HTML form within view

Zend newbie here ... And just to make it better, my mission is to build on top of someone else's pre-existing Zend site.

(BTW: zf show version --> Zend Framework Version: 1.11.1 -- I seem to have Zend_Form).

Here's the curious bit. All the forms are built in HTML within views. They seem to work, although I can't figure out how -- especially given what I am seeing.

I followed the convention and created a view for a test form and wrote the form:

<form action="<?php echo $this->url(array('controller'=>'ControllerName','action'=>'submit'));?>" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
   <input class="text"  type="text name="custEmail"/>
</div>
<div class="field">
   <input class="button" value="Submit and be free!" type="submit"/>
</div>
</form>

The submitAction member in the controller is firing correctly. No problem.

But ALL the places I could look for the POST data appear to be empty!

        echo "obj  custEmail = [开发者_StackOverflow" . $this->_request->getPost('custEmail') . "]\n";
        echo "GET  custEmail = [" . $_GET['custEmail'] . "]\n";
        echo "POST custEmail = [" . $_POST['custEmail'] . "]\n";

        if ($this->_request->isPost()) {
           $data = $this->_request->getPost();
           Zend_Debug::dump($data);
        }

They all produce nothing.

I'd be much obliged for a solution or even a clue about what is going wrong.

Thanks for reading.


Your form is not in the correct format.As it's PHP you can use form like this or you can even generate a ZEND_FORM(which is profound way to do it).It's always a good practise to work around with ZEND_FORM.If you still want to use this and the go by your way,here is th snippet I modified for you.

I am modifying the Code for you.Your View should have this form in it;

<form action="" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
   <input class="text"  type="text" name="custEmail"/>
</div>
<div class="field">
   <input class="button" value="Submit and be free!" type="submit" name="submit"/>
</div>
</form>

<?php
echo $this->custEmail;
?>

Now write the following one on your ACTIOn,i.e. submitAction;

public function submitAction()
{
  if ($this->getRequest()->isPost())
  {
    $custEmail = $this->getRequest()->getPost('custEmail');
    echo $custEmail;
    $this->view->custEmail = $custEmail;
  }

}

Now check if it works for you or not.


Create a form using Zend_Form. When ZF already has a way to create forms, you should use that. Your method is like a hack and is not a recommended way to do things.

Check here on how to create a Zend_Form

http://framework.zend.com/manual/en/zend.form.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜