I have a drop down list where users can select a theme for the site. The only problem is, I'm not quite sure how to properly load the theme once they press "Apply". I am new to PHP. I know if I use GET, it will pass the variables through a the current page and add them to the end of the URL. I would really like to avoid that. So, I guess my question is, how can I avoid using GET to update the theme? Thank you.
Here is my code to load the correct theme:
<?php
$stylesArr = array('Default', 'Black', 'Pink', 'Green', 'Red');
if(isset($_GET['theme']) && in_array($_GET['theme'], $stylesArr)) {
$style = $_GET['theme'];
setcookie("theme", $style, time()+(60*60*24*30));
} else {
if(isset($_COOKIE['theme']) && in_array($_COOKIE['theme'], $stylesArr)) {
$style = 'CSS/' . $_COOKIE['theme'] . '.css';
} else {
$style = 'CSS/Default.css';
}
}
?>
Here is my drop down list to select the theme:
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
<p>Site Theme:
<select name="theme">
<option value="Default">Default</option>
<option value="Black">Black</option>
<option value="Pink">Pink</option>
<option value="Green">Green</option>
<option value="Red">Red</option>
</select>
<input type="submit" value="Apply" />
</form>