Page 1 of 1

Passing variables from form to form

Posted: Fri Sep 19, 2008 1:18 pm
by TylerK
Hello!

I'm currently working on a site for for a small insurance agency and they have a 'enter your zip and get a quote' form input on the homepage and subpages, what I am trying to accomplish is getting that zip code to pass into the quote form on another page.

I've setup a test here, and it's simple enough to get working in regular old php, but I for the life of me haven't been able to figure out how to get this simple function -

Code: Select all

<?php 
     $zip = $_POST['zip']; 
     echo "<input type=\"text\" value=\"$zip\" >"; 
?> 
To work inside {php} tags. (They're turned on in the config.php)

Any help would be greatly appreciated as I'm at my wits end on this one. Thanks in advance!

Re: Passing variables from form to form

Posted: Fri Sep 19, 2008 7:22 pm
by Augustas
You can access your POST or GET variables with the Smarty, so you do not have to enable {php} tags.

Access your ZIP code like this:

Code: Select all

{$smarty.request.zip}
or

Code: Select all

{$smarty.post.zip}
Read more about this in Smarty documentation:

Code: Select all

{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
{$smarty.get.page}
{* display the variable "page" from a form ($_POST['page']) *}
{$smarty.post.page}
{* display the value of the cookie "username" ($_COOKIE['username']) *}
{$smarty.cookies.username}
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}
{* display the system environment variable "PATH" *}
{$smarty.env.PATH}
{* display the php session variable "id" ($_SESSION['id']) *}
{$smarty.session.id}
{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username}

Re: Passing variables from form to form

Posted: Fri Sep 19, 2008 7:55 pm
by TylerK
Oh Brilliant! It worked perfectly, thank you very much!

I think I'm going to spend the weekend reading the smarty resources site, thanks again :)

Re: Passing variables from form to form

Posted: Fri Sep 19, 2008 7:58 pm
by Augustas
Or you can just download Smarty documentation PDF:
http://www.smarty.net/download-docs.php