DeathStar Posted November 22, 2006 Share Posted November 22, 2006 How can i have something like..Users can change site colors by choosing a color from a checkbox?like [list][*]Red[*]Blue[*]Green[/list] [table][tr][td][sub]Submit[/sub][/table] Quote Link to comment Share on other sites More sharing options...
CheesierAngel Posted November 22, 2006 Share Posted November 22, 2006 1) Pass a color or theme variable to the page and on base of the color passed you can load a different css file.2) Store the color or theme variable in a database, session, whatever to determine each time which color to use.3) ...[code]<html> <head> <title>Page Title</title> <link rel="stylesheet" href="css/<?php echo $_REQUEST['theme']; ?>.css" type="text/css"/> </head> <body> </body></html>[/code] Quote Link to comment Share on other sites More sharing options...
CheesierAngel Posted November 22, 2006 Share Posted November 22, 2006 Example:[code]<?php $color = "greenyellow"; /* Default color */ if(isset($_REQUEST['color'])) { /* If color form submitted */ $color = $_REQUEST['color']; }?><html> <head> <title>ColoringPage</title> </head> <body bgcolor="<?php echo $color; ?>"> <h1>Chooze your background color:</h1> <form action="coloringPage.php" method='post'> <ul> <li><input type="radio" name="color" value="chocolate">chocolate</input></li> <li><input type="radio" name="color" value="burlywood">burlywood</input></li> <li><input type="radio" name="color" value="dodgerblue">dodgerblue</input></li> <?php /* and so on */ ?> </ul> <input type="submit" value="Change Color" /> </form> </form> </body></html>[/code]Didn't tested this code but the logic is all there. Quote Link to comment Share on other sites More sharing options...
DeathStar Posted November 22, 2006 Author Share Posted November 22, 2006 Nope it still stays the same colors!?! :'( Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 22, 2006 Share Posted November 22, 2006 Please post the code you're using.Ken Quote Link to comment Share on other sites More sharing options...
DeathStar Posted November 22, 2006 Author Share Posted November 22, 2006 This is the exact code im using![code]<?php $color = "#990099"; /* Default color */ if(isset($_REQUEST['red'])) { /* If color form submitted */ $color = $_REQUEST['blue']; }?><html> <head> <title>ColoringPage</title> </head> <body bgcolor="<?php echo $color; ?>"> <center><font color=#66ff00><h2>Choose your background color:</h2></font></center> <form action="coloringPage.php" method='post'> <ul> <li><input type="radio" name="color" value="red"><font color=red>Red</font></input></li> <li><input type="radio" name="color" value="blue"><font color=blue>Blue</font></input></li> <li><input type="radio" name="color" value="green"><font color=green>Green</font></input></li> <?php /* and so on */ ?> </ul> <input type="submit" value="Change Color" /> </form> </form> </body></html>[/code] Quote Link to comment Share on other sites More sharing options...
mansuang Posted November 22, 2006 Share Posted November 22, 2006 [quote author=DeathStar link=topic=115900.msg472189#msg472189 date=1164220661]This is the exact code im using![code]<?php $color = "#990099"; /* Default color */ if(isset($_REQUEST['red'])) { /* If color form submitted */ $color = $_REQUEST['blue']; }?><html> <head> <title>ColoringPage</title> </head> <body bgcolor="<?php echo $color; ?>"> <center><font color=#66ff00><h2>Choose your background color:</h2></font></center> <form action="coloringPage.php" method='post'> <ul> <li><input type="radio" name="color" value="red"><font color=red>Red</font></input></li> <li><input type="radio" name="color" value="blue"><font color=blue>Blue</font></input></li> <li><input type="radio" name="color" value="green"><font color=green>Green</font></input></li> <?php /* and so on */ ?> </ul> <input type="submit" value="Change Color" /> </form> </form> </body></html>[/code][/quote]On line 3,4 You should change [color=red]$_REQUEST['red'][/color] to [color=blue]$_REQUEST['color'][/color]and [color=red]$_REQUEST['blue'][/color] to [color=blue]$_REQUEST['color'][/color]Hope it works fine Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 22, 2006 Share Posted November 22, 2006 Why are you doing this[code]<?php if(isset($_REQUEST['red'])) { /* If color form submitted */ $color = $_REQUEST['blue']; }?>[/code]You need to use something like this:[code]<?php $color = "#990099"; /* Default color */ if(isset($_POST['submit'])) { /* If color form submitted */ $color = $_POST['color']; // the name of the posted variable is "color" }?><html> <head> <title>ColoringPage</title> </head> <body bgcolor="<?php echo $color; ?>"> <center><font color=#66ff00><h2>Choose your background color:</h2></font></center> <form action="coloringPage.php" method='post'> <ul> <li><input type="radio" name="color" value="red"><font color=red>Red</font></input></li> <li><input type="radio" name="color" value="blue"><font color=blue>Blue</font></input></li> <li><input type="radio" name="color" value="green"><font color=green>Green</font></input></li> <?php /* and so on */ ?> </ul> <input type="submit" value="Change Color" name="submit"/> </form> </form> </body></html>[/code]Notice that I also gave the "submit" button a name, so we could test whether it was pressed.Ken Quote Link to comment Share on other sites More sharing options...
DeathStar Posted November 22, 2006 Author Share Posted November 22, 2006 Thanx it works now!if this is not asking to much is there any way i can edit font and text color? Quote Link to comment Share on other sites More sharing options...
CheesierAngel Posted November 23, 2006 Share Posted November 23, 2006 Thats no problem, you add a new list to your form with radiobuttons the choose the font.[code]<?php $color = "#990099"; /* Default color */ $fontType = "arial"; /* Default font type */ if(isset($_POST['submit'])) { /* If color form submitted */ if(isset($_POST['color'])) { $color = $_POST['color']; // the name of the posted variable is "color" } if(isset($_POST['fontType'])) { $fontType = $_POST['fontType']; } }?><!-- Your form -->[/code]You can add as many changable variables as you wich. Keep in mind that you actually needto use all customizable variables over your page. You should make a function that does this for you.[code]<?php function _t($text) { global $fontColor; global $fontSize; /* And all other customizable variables */ return "<font color='$fontColor' size='$fontSize' /* and all the rest */>" . $text . "</font>"; }?><body> <?php echo _t("This text is customizable!"); ?> <!-- your form --></body>[/code] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 23, 2006 Share Posted November 23, 2006 there isnt really a point in checking if $_POST['color'] is set and same with fontType. but i would check if they are blank, if so set defaults. Quote Link to comment Share on other sites More sharing options...
DeathStar Posted February 14, 2007 Author Share Posted February 14, 2007 ok thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.