I am trying to update a block of code with value's sent through a form however I am having trouble updating the whole block of code. The number of inputs change based on the code. For example:
.btn-primary{
color: @color;
font-style: none;
background-color: @background-color;
transition: all .75s;
text-transform: uppercase;
font-weight: @font-weight;
&:hover{
background-color: darken(@background-color, 10%);
font-style: none;
color: @color;
}
}
I am able to sucessfully find the @ variables and display the correct number of <input>'s based off the code. The problem I am having is having my foreach loop run through each $_POST value and updating the code. The best result I have been able to get is the first $_POST value but then it cuts off.
function replace_code($code){
foreach($_POST as $name => $value){
return str_replace($name, htmlentities($value), htmlentities($code));
}
}
In the case of .btn-primary when I fill out my inputs and submit the form the best I can get is the first value to update and that is it. If I were to put #fff in the @color field and other values into @background-color and @font-weight and run my function once submit is set, I get the output of.
.btn-primary{
color: #fff;
font-style: none;
background-color: @background-color;
transition: all .75s;
text-transform: uppercase;
font-weight: @font-weight;
&:hover{
background-color: darken(@background-color, 10%);
font-style: none;
color: #fff;
}
}
Any idea's on how I can get that foreach loop to keep updating the code.