TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   POST Metod in Zend Framework (http://www.talkphp.com/absolute-beginners/2458-post-metod-zend-framework.html)

krum 03-11-2008 11:54 AM

POST Metod in Zend Framework
 
Can you show me some example how to get variables with POST Method.

Alan @ CIT 03-11-2008 12:05 PM

Hi Krum,

Here is a small example:

PHP Code:

<?php
class IndexController extends Zend_Controller_Action
{
    public function 
indexAction()
    {
        
// Our post array: ['name'] => 'Alan', ['country'] => 'UK'
        
        // Check for a POST request
        
if ($this->_request->isPost())
        {
            
// Get the 'name' and 'country' values from the $_POST array
            
$name $this->_request->getPost('name');
            
$country $this->_request->getPost('country');
            
            echo 
'Hello ' $name ' from ' $country '!';            
        }

    }
}

Edit: (and Welcome to TalkPHP :-))

Alan

krum 03-11-2008 12:13 PM

Thanks Alan, I work on mail form, so my problem is how to connect controller with view index page.

Alan @ CIT 03-11-2008 12:23 PM

Hi Krum,

I'm not sure what you mean. Are you trying to include the output from your mail controller in your index view?

If so, take a look at the ActionStack helper. This should do what you need.

Alan

krum 03-11-2008 12:37 PM

Thanks Alan, I have mail form, where user will send mail to me,(mail, name, subjet, body...). So I want to take data with post method in controller and send email. I will send code that I want to use with Zend Framework.
<html>
<body>

Code:

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail( "krum@example.com", "Subject: $subject",
  $message, "From: $email" );
  echo "Your email is send";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

</body>
</html>


krum 03-11-2008 03:17 PM

Thanks Alan, it help me a lot.

Quote:

Originally Posted by Alan @ CIT (Post 12244)
Hi Krum,

Here is a small example:

PHP Code:

<?php
class IndexController extends Zend_Controller_Action
{
    public function 
indexAction()
    {
        
// Our post array: ['name'] => 'Alan', ['country'] => 'UK'
        
        // Check for a POST request
        
if ($this->_request->isPost())
        {
            
// Get the 'name' and 'country' values from the $_POST array
            
$name $this->_request->getPost('name');
            
$country $this->_request->getPost('country');
            
            echo 
'Hello ' $name ' from ' $country '!';            
        }

    }
}

Edit: (and Welcome to TalkPHP :-))

Alan



All times are GMT. The time now is 06:52 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0