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
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
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
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
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
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
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.