V
V
viktorross2019-05-30 16:38:09
PHP
viktorross, 2019-05-30 16:38:09

Why doesn't counting work in php and smarty?

Hello, I have such a problem, there
is the same output in the template on 3 pages

{if isset($credits_allowed) && $credits_allowed && !$nologin}

<div class="option clearfix" id="div_credits" {if !$total}style="display: none;"{/if}>

<input type="hidden" name="credit_value" id="credit_value" value="{$credits_settings.unit}"/>

<input type="hidden" name="current_credits" id="current_credits" value="{$current_credits}"/>

<div class="option_left">{$lng.credits.balance}</div>

<div class="option_right"><b>{if $current_credits>0}{$lng.credits.you_currently_have} <span class="price">

{$current_credits} 

{if $current_credits==1}{$lng.credits.scredit}{else}{$lng.credits.scredits}{/if}</span>{else}

{$lng.credits.you_currently_have_no_credits}{/if}</b><br/>

<br/>

<label style="line-height: 30px;" class="freeradiog">

<input type="radio" class="noborder" name="processor" value="credits"  

{if $current_credits>=$needed_credits}checked="checked"{else}disabled="disabled"{/if}/>

<div class="radio__textg"></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

{$lng.credits.pay_using_credits}<span id="not_enough_credits" {if $current_credits==0 || 

$current_credits>=$needed_credits}style="display: none;"{/if}>

( {$lng.credits.not_enough_credits} )</span>

<!--<span id="no_credits" {if $current_credits==0 || $current_credits<$needed_credits}style="display: none;"

{/if}> ( <span id="needed_credits">{$needed_credits}</span> <span id="scredit"

{if $needed_credits>1}style="display: none;"{/if}>{$lng.credits.scredit}</span>

<span id="scredits" {if $needed_credits==1}style="display: none;"{/if}>{$lng.credits.scredits}</span> )--> 

</span>
  </label>
  </div>
  </div>
  {/if}

on page 2 it works, on page 3 for some reason this line does not work, I had to hide it, because the reason why it does not work is not clear to me
<!--<span id="no_credits" {if $current_credits==0 || $current_credits<$needed_credits}style="display: none;"

{/if}> ( <span id="needed_credits">{$needed_credits}</span> <span id="scredit"

{if $needed_credits>1}style="display: none;"{/if}>{$lng.credits.scredit}</span>

<span id="scredits" {if $needed_credits==1}style="display: none;"{/if}>{$lng.credits.scredits}</span> )-->

the essence is that when the user has enough points, the required number appears in brackets and the input is unlocked, if you click on the button that should add more to the required points, then nothing is updated, namely the value $needed_credits, if more points are selected than the user has, then it should instead of numbers, the inscription "not enough points" appears here {$lng.credits.pay_using_credits}and all this should happen without refreshing the page, but this does not happen. The current value of how many points the user has is this line $current_creditswith which the required points are compared $needed_credits. $needed_creditsBut for some reason, the script cannot add the selected values ​​to , respectively, and cannot compare with $current_creditseither. But php knows for sure that points are still not enough, so further actions are impossible.
So what's the problem? after all, exactly the same template works on 2 pages as it should ..
Maybe JS is to blame, maybe php what to look at?
Why can this happen?
By the way, if the needed_credits value is equal to 0, then all this is shown in full, i.e. all texts that are hidden and should be shown under certain conditions
<!--<span id="no_credits" {if $current_credits==0 || $current_credits<$needed_credits}style="display: none;"

{/if}> ( <span id="needed_credits">{$needed_credits}</span> <span id="scredit"

{if $needed_credits>1}style="display: none;"{/if}>{$lng.credits.scredit}</span>

<span id="scredits" {if $needed_credits==1}style="display: none;"{/if}>{$lng.credits.scredits}</span> )-->

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2019-05-30
@SilenceOfWinter

there should be errors in the logs, most likely not all variables were transferred. It's easier to use "{if (!empty($needed_credits))}" instead of "{if $needed_credits==1}" and "{if $needed_credits>1}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question