Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

post back value from smarty template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
unidude
Smarty n00b


Joined: 27 Jun 2005
Posts: 2

PostPosted: Mon Jun 27, 2005 5:26 am    Post subject: post back value from smarty template Reply with quote

Hi all,

just a quick question

if i want to return back a reserved variable with a value say name='postback'
*in thisTemplate.tpl*
{$smarty.server.post['postback'] = 'thisvalue'}

so that I can catch it in <?php

$postbackValue = $_pos['postback'];

?>

Thanks in advance
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Jun 27, 2005 2:13 pm    Post subject: Reply with quote

You create a form on a template:

Code:
<form action="{$SCRIPT_NAME}">
<input type="hidden" name="postback" value="thisvalue">
<input type="submit">
</form>


When the form submits, the value is available in PHP: $_POST['postback']

Or, create a link in a template:

Code:
<a href="{$SCRIPT_NAME}?postback=thisvalue">click</a>


Click the link and the value is available in PHP: $_GET['postback']
Back to top
View user's profile Send private message Visit poster's website
unidude
Smarty n00b


Joined: 27 Jun 2005
Posts: 2

PostPosted: Mon Jun 27, 2005 11:34 pm    Post subject: Reply with quote

Thanks mohrt

I probablly didnt explain it better....sorry about that...

I have an IF statement in the template in which

{if condition true}
postback thisName = 'thisValue'
{else}
<select name='postback'>
<option value='value1'>value1</option>
<option value='value2'>value2</option>
...........................etc....
</select>



so what I am trying to achieve is when the condition is true it only displays a label field (not a text box , or a drop down list like if the condition is false) and I want to return that assigned value back to the php code from the template.

...later on I found what I did was to add the following code

<input type="hidden' name='postback' value='thisValue'>

it works fine....
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jun 28, 2005 1:32 pm    Post subject: Reply with quote

Yep thats what I do, make it a hidden field.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP