Jump to content

Changing Colors


DeathStar

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/28104-changing-colors/#findComment-128558
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/28104-changing-colors/#findComment-128615
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/28104-changing-colors/#findComment-128706
Share on other sites

[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
Link to comment
https://forums.phpfreaks.com/topic/28104-changing-colors/#findComment-128716
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/28104-changing-colors/#findComment-128719
Share on other sites

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 need
to 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]
Link to comment
https://forums.phpfreaks.com/topic/28104-changing-colors/#findComment-129056
Share on other sites

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.