I have the most annoying PHP ever encountered. I need to submit the page TWICE before the changes are being made to the page. For example; if you submit the page when you enable a tool, it will show the tools' settings: for these settings to show up you need to submit the page twice. What is wrong with this code?
CODE:
<?php
if (isset($_POST["submit"]))
{
$string = '<?php
$customoptions = ' . $_POST["customoptions"] . ';
$primarycolor = "' . $_POST["primarycolor"] . '";
$adminbg = "' . $_POST["adminbg"] . '";
?>';
$fp = fopen("includes/userstyle.php", "w");
fwrite($fp, $string);
fclose($fp);
}
?>
<form action="" name="customopt" method="post">
<table>
<tr>
<td>Panel language</td>
<td>
<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option><?php echo $lang['chooselanguage']; ?></option>
<option value="dashboard.php?lang=en">English</option>
<option value="dashboard.php?lang=nl">Dutch</option>
</select>
</td>
</tr>
<tr>
<td>Custom Style</td>
<td>
<select name="customoptions" id="customoptions">
<option <?php echo ($customoptions == true) ? 'selected' : '' ?> value="true">
<?php echo $lang['enabled']; ?>
</option>
<option <?php echo ($customoptions == true) ? 'selected' : '' ?> value="false">
<?php echo $lang['disabled']; ?>
</option>
</select>
</td>
</tr>
<?php
if ($customoptions)
{
?>
<tr>
<td>Primary Color</td>
<td><input name="primarycolor" type="text" id="primarycolor" value="<?php echo $primarycolor; ?>"></td>
</tr>
<tr>
<td>Background Color</td>
<td><input name="adminbg" type="text" id="adminbg" value="<?php echo $adminbg; ?>"></td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" value="<?php echo $lang['ok']; ?>">
</form>
PS: I know this isn't a good way to save settings in a php file but this is just a test, it will never go live.