| View previous topic :: View next topic |
| Author |
Message |
bneeley Smarty Rookie
Joined: 14 May 2012 Posts: 5
|
Posted: Mon May 14, 2012 7:49 pm Post subject: accessing $_POST variables within an included tpl file |
|
|
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 |
|
rodneyrehm Administrator

Joined: 30 Mar 2007 Posts: 698 Location: Germany, border to Switzerland
|
Posted: Mon May 14, 2012 8:06 pm Post subject: |
|
|
{$smarty.post.itemType}? (you might want to set the name attribute) _________________ Twitter |
|
| Back to top |
|
bneeley Smarty Rookie
Joined: 14 May 2012 Posts: 5
|
Posted: Mon May 14, 2012 8:11 pm Post subject: |
|
|
| 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 |
|
bneeley Smarty Rookie
Joined: 14 May 2012 Posts: 5
|
Posted: Mon May 14, 2012 8:54 pm Post subject: |
|
|
| 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 |
|
bneeley Smarty Rookie
Joined: 14 May 2012 Posts: 5
|
Posted: Mon May 14, 2012 9:20 pm Post subject: |
|
|
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 |
|
rodneyrehm Administrator

Joined: 30 Mar 2007 Posts: 698 Location: Germany, border to Switzerland
|
Posted: Tue May 15, 2012 7:32 am Post subject: |
|
|
| 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 |
|
bneeley Smarty Rookie
Joined: 14 May 2012 Posts: 5
|
Posted: Tue May 15, 2012 1:30 pm Post subject: |
|
|
Major face palm! I can't believe I missed that!
Thanks for your patience and help. That worked. |
|
| Back to top |
|
|