Search code examples
phptemplatessmarty

If Else Operations doesnt work in .tpl file


I have this tpl file code which will represent 2 factor authentication validation

<form 
     action="../tiki-two_factor_validator.php" 
     method="POST">
     <div class="form-group">
            <label for="twoFactor">
                   {if isset($_GET.error)}
                       <div class="alert alert-danger">
                            {$_GET.error}
                        </div>
                    {else}
                        We send to your email two-factor authentication code
                    {/if}
            </label>
            <input type="text" class="form-control" id="twoFactor" name="twoFactor" placeholder="Two-Factor Code" required>
      </div>
      <button type="submit" class="btn btn-primary btn-block">Login</button>
</form>

but i got in html something like this:

enter image description here

What could be causing this error?

Edit* I have no problems with PHP, everything works as expected

if (isset($result[0])) {
        $attempts = $result[0]['attempts'] + 1;
        $query = "UPDATE tiki_2fa_tokens SET attempts = '$attempts' WHERE token = '$token'";
        TikiDb::get()->query($query);
    } else {
        header("Location: http://127.0.0.1:8080/tikiTwoFactor?error=Wrong token, please try again");
        exit();
    }
require_once('vendor_bundled/vendor/smarty/smarty/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->display('/templates/tiki_two_factor_auth.tpl');

when i am trying to access the page using route path (http://127.0.0.1:8080/tikiTwoFactor):

tiki_route_attempt(
        '|^tikiTwoFactor$|',
        'templates/tiki_two_factor_auth.tpl'
);

i am getting this errors in brawser, but when i am accessing using folder path (http://127.0.0.1:8080/tiki-two_factor_validator.php) everything seems okay

enter image description here


Solution

  • The problem was in displaying the interaction between a file like tpl and the router, I changed all the headers to the default smarty ->assign method and everything worked

            if ($seconds > 1800) {
                $smarty->assign('error', 'Expired token, please login again');
            } else {
                $attempts = $result[0]['attempts'] + 1;
                $query = "UPDATE tiki_2fa_tokens SET attempts = '$attempts' WHERE token = '$token'";
                TikiDb::get()->query($query);
            }
    

    .tpl

                        {if $error}
                            <div class="alert alert-danger">
                                {$error}
                            </div>
                        {else}
                            We send to your email two-factor authentication code
                        {/if}
    

    result enter image description here