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

how to evaluate a button in the template skript

 
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 -> General
View previous topic :: View next topic  
Author Message
The_Dragon
Smarty n00b


Joined: 11 Mar 2005
Posts: 3

PostPosted: Fri Mar 11, 2005 7:37 am    Post subject: how to evaluate a button in the template skript Reply with quote

Hello everyone,

how can I evaluate if a button is set or not in the the *.tpl file?
some code snippets:
*.php
...
$smarty->display('createuser.tpl');

//that works fine
if($new_user)
{
echo 'some html code';
}
...

*.tpl:
...
<form name="newuser" action="{php}echo $_SERVER['PHP_SELF'];{/php}" method="post"><input type="submit" name="new_user" type="button" class="button" value="neuer Nutzer"</td>
</form>

{* that doesn't work anyway ;/ *}
{if $new_user}
here should be the html output from the php if($new_user) Condition
{/if}
...

I'd like to separate the logical from the layout part, but can't figure out how I can put all html stuff into the template. Any hint available?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Mar 11, 2005 2:45 pm    Post subject: Reply with quote

It looks like you need to grasp the basic concepts of Smarty. I'd recommend reading the Crash Course from the Smarty website, then read through the manual once. You should avoid using {php}{/php} tags in the templates, there is always a better way. Also, don't assign HTML code to the templates, assign data that gets HTML markup within the templates.

Here is how you might rewrite the code you have:

[php:1:17bdcc394f]
$smarty->assign('new_user', $new_user);
$smarty->assign('new_user_text', 'Welcome new user!');
$smarty->display('createuser.tpl');
[/php:1:17bdcc394f]


Code:
<form name="newuser" action="{$smarty.server.PHP_SELF}" method="post">
<input type="submit" name="new_user" type="button" class="button" value="neuer Nutzer"</td>
</form>

{if $new_user}
{$new_user_text}
{/if}
Back to top
View user's profile Send private message Visit poster's website
The_Dragon
Smarty n00b


Joined: 11 Mar 2005
Posts: 3

PostPosted: Sat Mar 12, 2005 11:12 am    Post subject: Reply with quote

Your're right, I should have rtfm completely Wink.
I think I've got it now in the correct way?
The relevant code snippets:
create_user.tpl:
/***********/
{* Smarty *}

<table><tr><td align="center">
<form name="newuser" action="{$smarty.server.PHP_SELF}" method="post">
<input type="submit" name="new_user" type="button" class="button" value="neuer Nutzer"</td>
</form>
</tr></table>

{if $new_user}
<table class="bodyline" cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
</tr>
<tr>
<td>
<table>
<FORM ACTION="'.$PHP_SELF.'" METHOD="post" ONSUBMIT="javascript:return chkall();" NAME="myuser">
<tr><th>Gruppe:</th><td>
<select name="gruppe" size="1">
<option>user</option>
<option>admin</option>
</select>
<tr><th>Benutzername:</th><td><input name="name" type="text" MAXLENGTH="10"></td></tr>
<tr><th>UserID:</th><td><input name="userid" type="text" MAXLENGTH="10"></td></tr>
</tr>
<tr><th>Befehl:</th>
<td><input name="entry" type="submit" value=" OK ">&</td>
</tr>
</FORM>
</table>
</td>
</tr>
</table>
{/if}
/***********/

create_user.php:
/***********/
$smarty->assign('new_user', $new_user);
$smarty->display('createuser.tpl');
/***********/

Any comments welcome.
Back to top
View user's profile Send private message
The_Dragon
Smarty n00b


Joined: 11 Mar 2005
Posts: 3

PostPosted: Sat Mar 12, 2005 12:02 pm    Post subject: Reply with quote

The second form should be written of course also with the Smarty Server Variable:
/***********/
FORM ACTION="{$smarty.server.PHP_SELF}" METHOD="post" ONSUBMIT="javascript:return chkall();" NAME="myuser">
/***********/

Btw, a nice way to access the PHP_Self variable ;D.

Greetings from lower Saxony

The_Dragon
Back to top
View user's profile Send private message
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 -> 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