html - PHP - Page needs Twice a Submit to show Changes -
this question has answer here:
i have annoying php ever encountered. need submit page twice before changes being made page. example; if submit page when enable tool, show tools' settings: these settings show need submit page twice. wrong 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: know isn't way save settings in php file test, never go live.
ok, try has top says if (isset($_post['submit'])) try , give default value if isn't set. if (!(isset($_post['submit']))) i'm referrin $customoptions variable $primarycolor , $adminbg

Comments
Post a Comment