0

I have this form that allows you to choose a background color and text color. Once this is submitted, I want the data to change my stylesheet. Can I do this without entering the values in a database? Here is my form:

<form method="post" action="blog_settings.php">
<label for="change_background_color">Change Background Color</label>
<br>
<input type="color" name="change_background_color" id="change_background_color">
<br>
<label for="change_text_color">Change Text Color</label>
<br>
<input type="color" name="change_text_color" id="change_text_color">
<br><br>
<input type="submit" value="Submit" id="submit" onclick="return confirm('Are you sure?')">
</form>

Here are my post values:

<?php    

    if (isset($_POST['change_background_color'])){
        $change_background_color = $_POST['change_background_color'];
        }

    if (isset($_POST['change_text_color'])){
        $change_text_color = $_POST['change_text_color'];
        }   

?>

Here's how I plan to alter my CSS:

body {
  background-color: <?php echo $change_background_color ?>;
  color: <?php echo $change_text_color ?>;
}

I know I'm missing a step here. Can I do this without entering the color values into a database?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Julian
  • 97
  • 1
  • 1
  • 9
  • better try jquery on submit event – shashi Oct 13 '17 at 05:45
  • try to do in jquery. Refer this https://stackoverflow.com/questions/16625618/javascript-change-color-of-text-and-background-to-input-value – KMS Oct 13 '17 at 05:49

1 Answers1

2

Yes you need to save the settings somewhere otherwise they will not persist. Plus, you need to provide fallback values if you want your page to render properly.

The easiest way to persist data is to store it in PHP Session store.

Scriptonomy
  • 3,975
  • 1
  • 15
  • 23