2

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 = [" . $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.

Charles
  • 50,943
  • 13
  • 104
  • 142
confused
  • 31
  • 1
  • 4
  • I don't know if this is intentional, but line 4 of your first example has the word type="text without the trailing semilcolon... – VOIDHand May 25 '11 at 02:36

2 Answers2

8

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.

Nishant Shrivastava
  • 2,113
  • 3
  • 26
  • 43
1

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

Sumit Ghosh
  • 3,264
  • 4
  • 40
  • 59
  • Would much like to but have not yet been able to figure out how to get Zend autoloader/routing to find form definition files. Apart from that, I would still like to figure out the answer to my original question -- whether or not this is a hack -- of WHY the $_POST data is empty and/or how to get at it. – confused Dec 06 '10 at 21:42