Account Settings using <select>

SaW

Member
Mar 3, 2018
101
15
So after searching for answer on google ive decided to ask here:

I want my account settings in CMS to be chosen using a dropdown instead of having a textinput, but i don't know how to set this up as I've got no knowledge on the matter.
Code:
<p><label>Setting:<select>
           <option value="{acc_trade}">Enable Trading</option>
           <option value="{acc_trade}">Disable Trading</option>
</select></label></p>

           <p><label>Setting:<input type="text" name="acc_trade" size="32" maxlength="32" value="{acc_trade}" id="avatarmotto"></label></p>

Outputs this:
You must be registered for see images attach

But how can i make so that opt1 sets {acc_trade} to 0 while opt2 sets it to 1?

Hope i've explained myself correctly and any help will be very appreciated, thx.
 

Synapse

PogChamp
Mar 3, 2012
164
59


Code:
<?php
if(isset($_POST['toggleTrading'])) {
    if($_POST['toggleTrading'] != 0 AND $_POST['toggleTrading'] != 1){
        // bad data about to be submitted, escape it
        die("Unable to post that to database");
    }
    else {
        //update row
    }

}
?>
<p>
    <label>
        Setting:
        <select name="toggleTrading">
            <option value="1">Enable Trading</option>
            <option value="0">Disable Trading</option>
        </select>
    </label>
</p>
<p>
    <label>
        Setting:
        <input type="text" name="acc_trade" size="32" maxlength="32" value="{acc_trade}" id="avatarmotto">
    </label>
</p>

The code you want would look similar to this. My PHP skills are kind of bad however, sure there are better implementations.

Edit: forgot the semi colon, Python got me messin up.
 

SaW

Member
Mar 3, 2018
101
15
Will this work for the whole page if i want to be able to set all the different settings and then hit save to remember them?
Going for something that looks like this:
You must be registered for see images attach
 

Synapse

PogChamp
Mar 3, 2012
164
59
Will this work for the whole page if i want to be able to set all the different settings and then hit save to remember them?
Going for something that looks like this:
You must be registered for see images attach
Yeah, you just set an id to the whole form similar to how you do the select. Then do an if statement for $_POST['idYouSpecifiedforForm']

so basically

Code:
if(isset($_POST['idYouSpecifiedforForm'])){
    if(isset($_POST['idforSelect'])){
        //do stuff
    }
    if(isset($_POST['idforField'])){
        // do stuff
   }
   ...
 

Jerry

not rly active lol
Jul 8, 2013
1,957
522
I did something like this (from my old CMS back in 2016):

Code:
if (isset($_POST['onlineVisible']))
        {
            $ovis = $app->filter($_POST['onlineVisible']);
            
            if ($users->getUserVariable($_SESSION['user']['id'], 'hide_online') != (($ovis == false) ? '1' : '0'))
            {
                $success = 'Your account settings has been successfully updated.';
                $db->query("UPDATE `users` SET `hide_online` = '" . (($ovis == false) ? '1' : '0') . "' WHERE `id` = '" . $_SESSION['user']['id'] . "'");
            }
        }
        else
        {
            if ($users->getUserVariable($_SESSION['user']['id'], 'hide_online') != 1)
            {
                $success = 'Your account settings has been successfully updated.';
                $db->query("UPDATE `users` SET `hide_online` = '1' WHERE `id` = '" . $_SESSION['user']['id'] . "'");
            }
        }
        
        if (isset($_POST['friendRequestsAllowed']))
        {
            $fr_b = $app->filter($_POST['friendRequestsAllowed']);
            
            if ($users->getUserVariable($_SESSION['user']['id'], 'block_newfriends') != (($fr_b == false) ? '1' : '0'))
            {
                $success = 'Your account settings has been successfully updated.';
                $db->query("UPDATE `users` SET `block_newfriends` = '" . (($fr_b == false) ? '1' : '0') . "' WHERE `id` = '" . $_SESSION['user']['id'] . "'");
            }
        }
        else
        {
            if ($users->getUserVariable($_SESSION['user']['id'], 'block_newfriends') != 1)
            {
                $success = 'Your account settings has been successfully updated.';
                $db->query("UPDATE `users` SET `block_newfriends` = '1' WHERE `id` = '" . $_SESSION['user']['id'] . "'");
            }
        }
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
You should use JavaScript to prevent the number of calls to the server


Have each DIV box with it's own form and php handler. Make each div display none and give it an ID.

on the select for your form put onchange="myFunction()"

<script>
function myFunction(){
hide all element, then execute the lower code
if value of select == "this"
getelementbyid("this").style.display = "block";
}
</script>

You can use google and w3schools to figure out the rest
 
Last edited:

Users who are viewing this thread

Top