...

View Full Version : custom css from a form?



Ranger56
01-02-2006, 11:35 PM
I'm just learning php, stuff like


$a = "X";
echo $a;
$a .= "Y";
echo $a;

And I was wondering if it's possible to make a form that people can say what they want the background color, font-color, font-family, etc.. to be?

Like, say theres a field for body background color, and they put in #449900, it would make $bodybg = #449900, then write it into a CSS file

Any help is appreciated.

Velox Letum
01-02-2006, 11:54 PM
Not too difficult. The HTML for the form would likely be the most difficult with different classnames and such. I also added tabs on the elements to be more semantic.


<?php
if (isset($_POST['submit'])) {
$css = 'body {' . "\n";
if ($_POST['background-color'] != NULL) {
$css .= ' background-color: ' . $_POST['background-color'] . ';' . "\n";
}
if ($_POST['color'] != NULL) {
$css .= ' color: ' . $_POST['color'] . ';' . "\n";
}
if ($_POST['font-family'] != NULL) {
$css .= ' font-family: ' . $_POST['font-family'] . ';' . "\n";
}
if ($_POST['font-size'] != NULL) {
$css .= ' font-size: ' . $_POST['font-size'] . ';' . "\n";
}
$css .= '}';

// Then we process the $css variable. We can write it to a file, or echo it out, whatever we need.
// We can even stop the form from outputting and output a few headers so the file is downloaded. Here I just echo it though.
echo $css;
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Body:<br />
Background-color: <input type="text" name="background-color" /><br />
Text color: <input type="text" name="color" /><br />
Font family: <input type="text" name="font-family" /><br />
Font size: <input type="text" name="font-size" /><br />
<input type="submit" name="submit" />
</form>

Ranger56
01-02-2006, 11:58 PM
awesome man
thanks alot, ill see if i can figure out how how this works!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum