Home > OS >  Using Php i want to know how to get a colour input from a user and set that colour to the background
Using Php i want to know how to get a colour input from a user and set that colour to the background

Time:10-26

I'm curious if I'm on the right track.

<?php
    $color = readline("Enter background: ");
    echo "<div style = 'background-colour:\'$color\' '";

?>

Any help would be appreciated, I'm really struggling with PHP :)

CodePudding user response:

So here we have to separate the problem into 3 parts.

1 -> Get the user input, which should be either HEX, RGB, RGBA wtv...

2 -> Get that value onto a variable so that you can later on dynamically assign it to your HTML tag (body I suppose) and set its background color to the value of that variable.

3 -> Assign the value of the variable to your html tag.

After doing some research, I found this line.

Which mixes, my logic in fewer steps haha, but the logic remains the same.

<?php echo '<input type="hidden" maxlength=100 name="value" id="val" value="'.$myobj->foo.'">';

You just need to change the to and it should work.

Lmk how that goes.

  • Related