John Davidson

html - input value on php form between pages

0 comments
Message:


I need you help. I have a form, and 2 inputs inside.
I have also those php code.
The idea is change css elements, by 2 colors the user insert, when my url is "URL?MyColors=true",
The function MyColors(), will run.
And then, the css apply by the inputs values.
I also want when client is submit, the url with get Get parameter "Mycolors=true",
so that why the submit button is with the next "formaction":
"".
It's work as well, but only for current page, and "URL2?MyColors=true".
When I'm refreshing the page, the 2 colors not apply anymore.
I don't know what the reason.
Who can help me?


<form action="" method="post" id="myform">
myColor1: <input name="myColor1" type="text" />
myColor2: <input name="myColor2" type="text" />
<input formaction="index.php?MyColors=true" type="submit" name="submit">
<button class="refresh" onclick="refreshPage()">Refresh</button>
</form>



<?php
if(isset($_GET['MyColors'])){
MyColors();
}

function MyColors() {
$_SESSION["myColors"] = "&MyColors=true";
if (isset($_POST['submit'])) {
$myColor1 = $_POST['myColor1'];
$myColor2 = $_POST['myColor2'];
}
else {
$myColor1 = $_SESSION['myColor1'];
$myColor2 = $_SESSION['myColor2'];
}

$_SESSION['myColor1'] = $_POST['myColor1'];
$_SESSION['myColor2'] = $_POST['myColor2'];

echo "<style>.bgimg-1{background: {$myColor1}!important;}
.last{color:{$myColor1}!important;-webkit-text-stroke-color:{$myColor2}!important;}
.first{color:{$myColor2}!important;-webkit-text-stroke-color:{$myColor1}!important;}
.addToCart{background:{$myColor1}!important;color:{$myColor2}!important;}
.addToCart i, a.addToCart a , a.addToCart span {color:{$myColor2}!important;}
.moreInfo{color: {$myColor1}!important;background: {$myColor2}!important;}
a.moreInfo i{color: {$myColor1}!important;}
button[type='button'].view_data {color: {$myColor1}!important;background: {$myColor2}!important;}
p.rotate {color: {$myColor1}!important; }
body {background: {$myColor2}!important;}
.categoriesTitle {color: {$myColor1}!important;}
.overlay {background: {$myColor1}!important;}
a.liAfter {color: {$myColor2}!important;}
.categoryTitles {color: {$myColor2}!important;background: {$myColor1}!important;}
.catWrapperImageCatPage::after {background: {$myColor2}!important;}
p.cat_title {color: {$myColor1}!important; }
</style>";
}
?>


My Answer:
http://example.com/form.php

Here is the HTML code for the form:

html















And here is the PHP code for processing the form data in `process.php`:

php
$color1 = $_POST['color1'];
$color2 = $_POST['color2'];
?>







Colors Changed!






When the user submits the form, the colors they entered will be used to change the background color and text color of the page.

Rate this post

3 of 5 based on 7290 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us