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

There's something wrong with my if/else condition in index.p

 
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
makamo66
Smarty Rookie


Joined: 21 Jun 2021
Posts: 5

PostPosted: Mon Jun 21, 2021 12:36 pm    Post subject: There's something wrong with my if/else condition in index.p Reply with quote

in index.php in the root directory I have:
Code:
if (isset($_REQUEST['form']) && !empty($_REQUEST['form']) ){
$form = $_REQUEST['form'];
$smarty->assign('form',$form);
}

if (isset($form)){
//assign a bunch of stuff using $form
}

else {
//display the template as the homepage
$smarty->display("templates/language/alphabet.tpl");
}


When I view my home page at localhost, I get the following errors:
Notice: Undefined index: form in C:\xampp\htdocs\projectname\templates_c\ecc481657059b848b2528d61c69a8548ceaaab4b.file.alphabet.tpl.cache.php on line 351

Notice: Trying to get property 'value' of non-object in C:\xampp\htdocs\projectname\templates_c\ecc481657059b848b2528d61c69a8548ceaaab4b.file.alphabet.tpl.cache.php on line 351

This is line 351 in the cached file:
Code:
<?php }elseif($_smarty_tpl->tpl_vars['form']->value==3){?>


It seems to be having a problem because there isn't a query parameter for the home page. The other pages look like this:
http://localhost/index.php?form=6
and the other pages with a query parameter don't show any errors.

This line of code in the cached version of alphabet.tpl comes right before line 351 and it doesn't throw an error:


Code:
<?php if (isset($_smarty_tpl->tpl_vars['form']->value)&&$_smarty_tpl->tpl_vars['form']->value==1){?>
<?php echo $_smarty_tpl->getSubTemplate ("language/widgets/".($_smarty_tpl->tpl_vars['language_widgets_1']->value).".tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 9999, null, array(), 0);?>

It's only showing the errors at localhost. At my domain name on the bluehost server, it doesn't show any errors. I am using a very old version, version Smarty-3.1.3
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Jun 23, 2021 4:11 pm    Post subject: Reply with quote

"Doesn't show errors" does not equal "no errors happening".

Show your template code, most likely you have something like

Code:
{if $form == 3} … {/if}
in there.

And I strongly suggest upgrading your Smarty right now.
Back to top
View user's profile Send private message
makamo66
Smarty Rookie


Joined: 21 Jun 2021
Posts: 5

PostPosted: Wed Jun 23, 2021 9:17 pm    Post subject: Reply with quote

Why do I need to upgrade my Smarty version if it's otherwise working fine? I think I found the problem based on your insight but I can't check it right now because I have to prepare for my bootcamp prep class that is starting in an hour. I will try to look at it and fix it tomorrow.
Back to top
View user's profile Send private message
makamo66
Smarty Rookie


Joined: 21 Jun 2021
Posts: 5

PostPosted: Thu Jun 24, 2021 11:48 am    Post subject: Reply with quote

Thanks, AnrDaemon, your idea was correct.

I had a whole bunch of elseif conditions in my template that didn't check whether the variable had been set or not. So I changed:

Code:
{if isset($form) && $form==1}
{include file="language/widgets/$language_widgets_1.tpl"}
{elseif $form==3}
{include file="language/widgets/$language_widgets_3.tpl"}

to:
Code:
{if isset($form) && $form==1}
{include file="language/widgets/$language_widgets_1.tpl"}
{elseif isset($form) && $form==3}
{include file="language/widgets/$language_widgets_3.tpl"}

That's just a snippet. There were actually more elseif conditions and none of them checked whether the variable had been set or not with isset. After I fixed this, all of the errors went away.
I still don't know why I need to upgrade my Smarty version.
Back to top
View user's profile Send private message
jonathan978123
Smarty n00b


Joined: 03 Mar 2021
Posts: 4

PostPosted: Wed Jun 30, 2021 5:16 pm    Post subject: Reply with quote

You'll want to upgrade smarty because you are using an old version.

Security fixes would be the main reason to keep smarty to date.
Back to top
View user's profile Send private message
makamo66
Smarty Rookie


Joined: 21 Jun 2021
Posts: 5

PostPosted: Mon Jul 19, 2021 11:51 pm    Post subject: Reply with quote

I'm having problems with my Smarty version on my localhost but it works for the website. My HTML is messed up on the localhost but I don't have the same stylesheet at the website so I don't know if my stylesheet is the problem or if my version is just too old.
Back to top
View user's profile Send private message
makamo66
Smarty Rookie


Joined: 21 Jun 2021
Posts: 5

PostPosted: Tue Jul 20, 2021 12:24 am    Post subject: Reply with quote

I commented out the stylesheet at localhost and I didn't have the same problem so my stylesheet is the problem, not the old version of Smarty.
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