私は次のコードを持っていますが、問題は、通常の送信ボタンを使用するとすべてが正常に機能することですが、jquery onchange でチェックボックスの値を送信したい場合は機能しません (つまり、データベースには何も入っていません)。onChange=this.form.submit()
追加の構造を使用して、jquery以外のルートに行ってみました。何が起こっているのか/これを修正する方法を知っている人はいますか? 私には、フォームがデータを処理せずに送信されているようです。
また、チェックボックスにhttps://github.com/ghinda/css-toggle-switchを使用しています
Jクエリ:
$('#construction').change(function() {
this.form.submit();
});
PHP:
<?php
$config = mysql_query("SELECT construction FROM config") or die(mysql_error());
$row_config = mysql_fetch_assoc($config);
if ($_POST) {
// 0 = off
// 1 = on
$constr = $_POST['construction'];
if ($constr == 'on') { $c = 0; } else { $c = 1; }
mysql_query("UPDATE config SET construction = '".$c."'") or die(mysql_error());
redirect('index.php');
}
?>
HTML:
<div style="margin-top:30px;">
<form action="index.php" method="post" id="doSite">
<fieldset class="toggle">
<input id="construction" name="construction" type="checkbox"<?php if($row_config['construction'] == '0') { echo ' checked'; } ?>>
<label for="construction">Site construction:</label>
<span class="toggle-button"></span>
</fieldset>
<input name="Submit" type="submit" value="Shutdown site" class="button">
</form>
</div>