Reply to Re: How to modify CSS with PHP?

Your name:

Reply:


Posted by randomname on 08/23/06 05:15

deko wrote:
> > or you can simply include a
> > <style type="text/css">... </style> for the background image in the
> > header of the page.
>
> That sounds easier than maintaining multiple stylesheets.
>
> Do this scenario sound correct:
>
> Put HTML buttons on the page, something like this:
>
> <form action="" method="post" name="newbackground">
> <input type="submit" value="white">
> <input type="submit" value="yellow">
> </form>
>
> Then, in the head section of the page, use PHP like this:
>
> <head>
> <style type="text/css">
> <?php
> if (!empty($newbackground = trim($_POST['white']))
> { ?>
> #page {
> background-image:url(/images/background-white.gif);
> <?php }
> elseif (!empty($newbackground = trim($_POST['yellow']))
> { ?>
> #page {
> background-image:url(/images/background-yellow.gif);
> <?php } ?>
> </style>
> </head>
>
> Is this correct? Something tells me I'm missing something on that form...
>
> Thanks for the help!

The $_POST array is keyed by the variable name... and your submit
buttons do not have names.

You should assign "name" attributes to your submit buttons, or use a
dropdown. I'd do it like this:

<select name=color>
<option value=yellow>yellow</option>
<option value=white>white</option>
</select>

then in your script:

<style>
<?php

$background = trim($_POST['color']);

if ($background = 'yellow'){
//yellow bg
}elseif ($background = 'blue'){
//blue bg
}else{
//default bg
}

But look ahead.. what happens when you want to change more than just
the background image? You should really just have separate themes in
separate css files, and load those corresponding stylesheets based on
the form input:

<?php

$theme = $_POST['theme']

if ($theme = 'yellow'){
//<link rel="StyleSheet" href="yellow.css" type="text/css">
}elseif ...

?>

inside the stylesheets you can define the entire theme and save
yourself a lot of work.

-sam

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация