Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts

    custom css from a form?

    I'm just learning php, stuff like

    Code:
    $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.

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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>
    Last edited by Velox Letum; 01-03-2006 at 01:30 AM.
    "$question = ( to() ) ? be() : ~be();"

  • #3
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    awesome man
    thanks alot, ill see if i can figure out how how this works!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •