我有以下php和html,因此用户可以选择日期&他们希望使用的时间格式并保存。一切正常,除非进行更改后,下拉框仍显示旧设置。要查看在下拉框中选择的新设置,我必须刷新页面。有没有办法让我在"节省时间设置"之后刷新/重新加载下拉菜单?单击按钮?
感谢您的帮助。
<?php
$date1 = date('m-d-Y | h:i A'); //12hr format
$date2 = date('m-d-Y | H:i'); //24hr format
$date3 = date('Y-m-d | h:i A'); //12hr format
$date4 = date('Y-m-d | H:i'); //24hr format
$date5 = date('d-m-Y | h:i A'); //12hr format
$date6 = date('d-m-Y | H:i'); //24hr format
//Read time setting from INI
$lines_array = file("modules/evolution/evolution.ini");
$search_string = "timesettings";
foreach($lines_array as $line) {
if(strpos($line, $search_string) !== false) {
list(, $new_str) = explode("=", $line);
$new_str = trim($new_str); //This line removes the spaces before and after.
}
}
$inicurrenttime = $new_str;
function MDY12HR() {
$timehtml = file_get_contents('modules/evolution/time/MDY12HR/top.html');
$tophtml = 'themes/Evolution/top.html';
file_put_contents($tophtml, $timehtml);
}
function MDY24HR() {
$timehtml = file_get_contents('modules/evolution/time/MDY24HR/top.html');
$tophtml = 'themes/Evolution/top.html';
file_put_contents($tophtml, $timehtml);
}
function YMD12HR() {
$timehtml = file_get_contents('modules/evolution/time/YMD12HR/top.html');
$tophtml = 'themes/Evolution/top.html';
file_put_contents($tophtml, $timehtml);
}
function YMD24HR() {
$timehtml = file_get_contents('modules/evolution/time/YMD24HR/top.html');
$tophtml = 'themes/Evolution/top.html';
file_put_contents($tophtml, $timehtml);
}
function DMY12HR() {
$timehtml = file_get_contents('modules/evolution/time/DMY12HR/top.html');
$tophtml = 'themes/Evolution/top.html';
file_put_contents($tophtml, $timehtml);
}
function DMY24HR() {
$timehtml = file_get_contents('modules/evolution/time/DMY24HR/top.html');
$tophtml = 'themes/Evolution/top.html';
file_put_contents($tophtml, $timehtml);
}
//code to change time settings
if(isset($_REQUEST['submittime'])){
$dropdownvalue=$_POST['timesetting'];
if($dropdownvalue == "MDY12HR"){
$func = 'MDY12HR';
$func();
}
if($dropdownvalue == "MDY24HR"){
$func = 'MDY24HR';
$func();
}
if($dropdownvalue == "YMD12HR"){
$func = 'YMD12HR';
$func();
}
if($dropdownvalue == "YMD24HR"){
$func = 'YMD24HR';
$func();
}
if($dropdownvalue == "DMY12HR"){
$func = 'DMY12HR';
$func();
}
if($dropdownvalue == "DMY24HR"){
$func = 'DMY24HR';
$func();
}
}
//code to write to ini file
$lines_array = file("modules/evolution/evolution.ini");
$search_string = "timesettings";
foreach($lines_array as $line) {
if(strpos($line, $search_string) !== false) {
list(, $new_str) = explode("=", $line);
$new_str = trim($new_str); //This line removes the spaces before and after.
}
}
$inicurrenttime = $new_str;
if(isset($_REQUEST['submittime'])){
$arr=glob("modules/evolution/evolution.ini"); //your ini file's path
$dropdownvalue=$_POST['timesetting'];
foreach($arr as $key=>$val){
$str=file_get_contents($val);
$str=str_replace($inicurrenttime, $dropdownvalue, $str);
file_put_contents($val, $str);
}
}
?>
<h2>Evolution Theme Time Settings</h2>
<div class="colorbox">
<br>
<label id="steps">Select the date & time setting for the Evolution theme.</label>
<br>
<br>
<form action="home.php?m=evolution" method="post">
<label for="color2">Current Date & Time Setting: </label>
<select name="timesetting" >
<option name="MDY12HR" value="MDY12HR" <?php if($inicurrenttime == "MDY12HR") echo "selected"; ?>>(MM/DD/YYYY | 12HR) Example: <?php echo ($date1) ?></option>
<option name="MDY24HR" value="MDY24HR" <?php if($inicurrenttime == "MDY24HR") echo "selected"; ?>>(MM/DD/YYYY | 24HR) Example: <?php echo ($date2) ?></option>
<option name="YMD12HR" value="YMD12HR" <?php if($inicurrenttime == "YMD12HR") echo "selected"; ?>>(YYYY/MM/DD | 12HR) Example: <?php echo ($date3) ?></option>
<option name="YMD24HR" value="YMD24HR" <?php if($inicurrenttime == "YMD24HR") echo "selected"; ?>>(YYYY/MM/DD | 24HR) Example: <?php echo ($date4) ?></option>
<option name="DMY12HR" value="DMY12HR" <?php if($inicurrenttime == "DMY12HR") echo "selected"; ?>>(DD/MM/YYYY | 12HR) Example: <?php echo ($date5) ?></option>
<option name="DMY24HR" value="DMY24HR" <?php if($inicurrenttime == "DMY24HR") echo "selected"; ?>>(DD/MM/YYYY | 24HR) Example: <?php echo ($date6) ?></option>
</select>
<br>
<br>
<input type="submit" name="submittime" value="Save Time Settings"/>
</form>
<br>
</div>
&#13;