How can i check if a post is set? isset($_POST['formname'])
I can't seem to find out how to do it in smarty?
{if isset($_POST['login'])}
Login is set!
{/if}
How can i check if a post is set? isset($_POST['formname'])
I can't seem to find out how to do it in smarty?
{if isset($_POST['login'])}
Login is set!
{/if}
You don't have to assign any data to Smarty in this case because request variables are simple visible in Smarty. So you can simple do that in your tpl file:
{if isset($smarty.post.username)}
Login is set!
{/if}
From comment I understand you want to do something else. Look at this code in template file:
{if isset($smarty.post.username)}
Username is set!
{if $smarty.post.username eq ''}
Empty username
{/if}
{/if}
<form name="form" method="post">
<input type="text" class="form-control" style="width:500px;" name="username" placeholder="Username or Email"><br>
<input type="password" class="form-control" style="width:500px;" name="password" placeholder="Password"><br>
<input type="submit" class="btn btn-info" style="width:500px;" name="login" value="Sign In"> </form>
When you first open site (and don't send form) no message is displayed because form has not been set and there is no $_POST data sent. But when you send form (without filling in anything) you will have message "Login is set" because form has been set and $_POST data are set although value of $_POST['login'] is empty string.
So in inner if you check if it's empty or not.
You can as alternative also use
{if isset($smarty.post.username) and ($smarty.post.username eq '')}
Username is set but it's empty!
{/if}