我有以下代码,但问题是,如果我使用正常提交按钮一切工作正常,但如果我想提交与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