我有以下代碼,但問題是,如果我使用正常提交按鈕一切工作正常,但如果我想提交與jQuery的onchange複選框值它不起作用(即沒有什麼是進入數據庫)...我試圖甚至去非jQuery的路線與onChange=this.form.submit()
追加到施工。任何人都知道最新情況/如何解決這個問題?對我來說,表單看起來好像是在不處理數據的情況下提交。jquery提交更改複選框
而且我使用:https://github.com/ghinda/css-toggle-switch的複選框
JQUERY:
$('#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>
幾乎好像處理複選框前的提交。任何想法爲什麼?數據不會進入db – Alex 2012-07-30 14:45:14
您是否使用'<?php print_r($ _ POST)?>'檢查了發佈的數據? – ocanal 2012-07-30 14:52:20