Admin Admin
Admin Admin

Reputation: 35

Pass value from <form> to button? with {if $' }

How to pass this {if $smarty.post.currency eq '2'}selected{/if} in button? so that button hrefs to "currency=2" ?

MY CURRENT CODE:

<form action="" method="post">
<label for="currency_sel">Currency:</label>
<select name="currency" id="currency_sel" class="form-control" onchange="submit();">
    <option value="1" {if $smarty.post.currency eq '1'}selected{/if}>saudi</option>
    <option value="2" {if $smarty.post.currency eq '2'}selected{/if}>dollar</option>
</select>   

I want to add this "{if $smarty.post.currency eq '2'}" to this

<li class="dropdown" id="currency-dropdown">
                                            <a class="dropdown-toggle" data-toggle="dropdown" href="#" style="color: white;">
                               <span>العملة</span> <b class="caret"></b>
                           </a>
                          <ul class="dropdown-menu">
                              <li><a href="index.php?currency=1"><img alt="SAR"src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Flag_of_Saudi_Arabia.svg/23px-Flag_of_Saudi_Arabia.svg.png" class="paises"><span>ر.س</span></a></li>      

Basically currenct code is working it selects that $smarty but i need to have href in it also for currency=2 so when current code selects it refreshes page, but i need to add to that refresh index.php?currency=2 , yes i can put it into form action="currency=2" but diffrent values should have diffrent actions.

Upvotes: 2

Views: 36

Answers (1)

a.mola
a.mola

Reputation: 4011

Bascially wrap it in PHP's opening and closing tag, but you said you want to use index.php?currency=2, which is a GET request. So I believe the only way to get that is by using $_GET['currency'] unless you know where you're getting that $smarty.post from

<form action="" method="post">
    <label for="currency_sel">Currency:</label>
    <select name="currency" id="currency_sel" class="form-control" onchange="submit();">
        <option value="1"<?php if ($smarty.post.currency == 1) echo 'selected';?>>saudi</option>
        <option value="2"<?php if ($smarty.post.currency == 2) echo 'selected';?>>dollar</option>
    </select>

Upvotes: 1

Related Questions