Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
accessing $_POST variables within an included tpl file

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
bneeley
Smarty Rookie


Joined: 14 May 2012
Posts: 5

PostPosted: Mon May 14, 2012 7:49 pm    Post subject: accessing $_POST variables within an included tpl file Reply with quote

I'm having issues getting the $_POST variable for the tpl file included in the tpl file, like this:

edit.tpl
Code:

{include file="link.tpl" alternate_directory="../admin/" returnType="url" urlName="pageurl" selectedUrl=$item.url required=true}


link.tpl
Code:

<input id="itemText" type="text" value="http://" title="Please enter a valid URL." style="width:100%;" class="url" />


How can I get the value of the input field in the POST variable?
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Mon May 14, 2012 8:06 pm    Post subject: Reply with quote

{$smarty.post.itemType}? (you might want to set the name attribute)
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
bneeley
Smarty Rookie


Joined: 14 May 2012
Posts: 5

PostPosted: Mon May 14, 2012 8:11 pm    Post subject: Reply with quote

how would I use the {$smarty.post.itemType} in my code? I'm still somewhat new to Smarty. I want to be able to access this variable from within my PHP code that is rendering these tpl files. (By the way, I'm still on Smarty 2)
Back to top
View user's profile Send private message
bneeley
Smarty Rookie


Joined: 14 May 2012
Posts: 5

PostPosted: Mon May 14, 2012 8:54 pm    Post subject: Reply with quote

Printing out the $smarty variable in my PHP code during and after the form has been processed shows that I don't have the value of the input field anywhere in the $smarty variable
Back to top
View user's profile Send private message
bneeley
Smarty Rookie


Joined: 14 May 2012
Posts: 5

PostPosted: Mon May 14, 2012 9:20 pm    Post subject: Reply with quote

This is what I'm expecting:

PHP
Code:

$itemText = $_POST['itemText'];


But 'itemText' isn't even a member of the $_POST variable! 'pageurl' is a member of the $_POST variable, but has an empty value! What's going on? The included tpl file (link.tpl) is in a form.
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Tue May 15, 2012 7:32 am    Post subject: Reply with quote

Quote:
<input id="itemText" type="text" value="http://" title="Please enter a valid URL." style="width:100%;" class="url" />


is missing the name attribute! instead you're setting the id attribute which, unless you need that in CSS or JS, gets you nowhere. <input> elements without a name a re not POSTed back to the server.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
bneeley
Smarty Rookie


Joined: 14 May 2012
Posts: 5

PostPosted: Tue May 15, 2012 1:30 pm    Post subject: Reply with quote

Major face palm! I can't believe I missed that! Embarassed

Thanks for your patience and help. That worked.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General 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