Anyone who is familiar in using Template Engines .. Such as smarty , please read this.

I have a page called edit_profile.php , where i allow my members to choose thing's such as their age , ethnicity , ect some drop down forms.

If i have form options , such as age ..

18
19
20
21
22 .. ect

And they select , let's say "22" , and submit the form , the age of 22 will be recorded into Mysql. Ok that's fine , great.

Now , the next time they goto edit_profile.php , how can i make the drop down box display the age they submitted?

Ive tried setting the "selected" option in the html form , but then whatever age they selected will show twice... 1 time b/c the age is an option in the list , and another b/c it's the age that is selected.

I dont want this , im trying to get the form to show the age they submitted , and only show in the drop down box 1 time.

If i can clarify what im trying to do further , please let me know , i really need some help with this , and im not sure how to do it.

    the part of the template creating the select-box and the content of the array you assign to the template var would be interesting

      It's not smarty that's creating the form .. it's just a regular HTML form ...

      I referenced smarty , b/c its the template engine i use .. it really has nothing to do with the problem at hand.

        Then I don't know what ou're talking about.

        Please show some code

          Ok ..

          Lets take this as an example ... It's drop down box where you can choose your Martial Status

          <select name="status" class="textbox" id="status">
                                <option>Single</option>
                                <option>Engaged</option>
                                <option>Married</option>
                                <option>Divorced</option>
                                <option>Widowed</option>
                                <option>Not Looking</option>
                                <option selected>{$status}</option>
                              </select>
          

          Now , When you submit the form , whatever option you choose will be recorded into the database , ok that works fine.

          Now , If you choose " Engaged " , the next time you view the form , you would want it to say engaged right? b/c thats what you chose ...

          Now i could query the database
          $sql = mysql_query(SELECT wed_status WHERE username = your username

          Then it would return "Engaged" b/c thats what you choose when you submitted the form ....

          Now how can i mak Enagaged appear as the chosen choice in the drop down box , the next time you view the edit account page?

          By using a selected tag on the form ... like this <option selected = {$selected)

          BUT then Engaged appears twice in the list ...... 1 time b/c its the result of the MYSQL query , and another time b/c its an option in the list .......

          Do you understand what im getting at?

            Assuming you have:
            $smarty->assign('WedStatus', $wedStatus);

            then you do:

            <select name="status" class="textbox" id="status">
                                  <option {if $WedStatus=='Single'}selected{/if}>Single</option>
                                  <option {if $WedStatus=='Engaged'}selected{/if}>Engaged</option>
            etc.
            

            on the other hand you could do:
            $WedStatusList = array('Single', 'Engaged', 'Married');
            $WedStatus = 'Single';
            (populate those vars automagically and assign them both to smarty)

            and THEN you'd do:

            <select name="status" class="textbox" id="status">
            {foreach item=$entry from=$WedStatusList}
              <option {if $WedStatus==$entry}selected{/if}>{$entry}</option>
            {/foreach}
            </select>
            

              Alright thanks for your help , so i needed to use if statements inside the template.

                Write a Reply...