S
S
SteepNET2020-02-17 20:18:37
SQL
SteepNET, 2020-02-17 20:18:37

Print values ​​from $_POST and $_COOKIE?

Good day!
I got confused with the task of displaying currencies on the site completely, I tried in different ways and through jquery, including ...
Site on Bitrix. There is a selector in the header, in the template. We send POST to the output and in cookies, there are no problems here, we remember everything as it should be.

$select = array('RUB'=>'','USD'=>'');
                            if(isset($_POST['select'])) {
                                setcookie("BX_CURRENCY",$_POST['select'], strtotime( '+30 days' ), SITE_DIR);
                                $select[$_POST['select']] = 'selected';
                            } elseif(isset($_COOKIE["BX_CURRENCY"])) {
                                $select[$_COOKIE["BX_CURRENCY"]] = 'selected';
                            }
                            ?>
                            <form method="post">
                                <select class="form-control form-control-sm d-sm-none d-md-block" name="select" onchange="this.form.submit()">
                                    <option value="RUB" <?=$select['RUB']?>>RUB</option>
                                    <option value="USD" <?=$select['USD']?>>USD</option>
                                </select>
                            </form>


Next, there is a certain table where you need to display the values ​​depending on the selection in the selector, or if they are not in $_COOKIE, then we show the default value, if there is an entry in $_COOKIE, then we output from it.

if ($_POST['select']=="RUB") {
     echo $arItem["PRICES"]["Base"]["PRINT_VALUE"];
}elseif ($_POST['select']=="USD") {
     echo "$ ".round(CCurrencyRates::ConvertCurrency($val, "RUB", "USD"), 2);


And then a dead end came, POST works fine, I add $_COOKIE processing, repeated values ​​\u200b\u200bare displayed if I set the default value like this
if ($_POST['select']=="") {
     echo $arItem["PRICES"]["Base"]["PRINT_VALUE"];
}

It works, but when selected in the POST selector, the values ​​\u200b\u200bare doubled, since the page needs to be updated to display $_COOKIE ...
Tried through switch\case , also not an option ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Savely, 2019-06-16
@lexstile

select count(*) from (select distinct w.id from words w join test t on t.word_id_1=w.id) ww ;

A
Aliy Kunashev, 2020-02-17
@askunash

Use kernel methods to work with cookies
https://dev.1c-bitrix.ru/api_d7/bitrix/main/web/co...5e4aeb90bcc95803145665.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question