How to change the background color of a html page using forms and php? -
after inputting color of choice page should change background color. should done using html forms.
<body bgcolor="<?php $_get["color"]; ?>"> <form method="get" name="color"> background color:<br> <input type="text" name="color"> <input type="submit" value="submit"> </form> </body>
you should use css instead of html attributes decorate html rendering. should avoid use inline styling represents better organization since it's separating languages (= separating css html).
so answer question, can :
<?php if (!isset($_get["color"]) || $_get["color"] === '') { $_get["color"] = 'pink'; } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>my website</title> <style> body { background-color: '<?= $_get["color"] ?>'; } </style> </head> <body> <form method="get" name="color"> background color:<br> <input type="text" name="color"> <input type="submit" value="submit"> </form> </body> </html>
Comments
Post a Comment