I have the following code, however the problem is that if I use a normal submit button everything works fine, but if I want to submit the checkbox value with jquery onchange it doesn't work (i.e. nothing is going into the db)... I tried even going the non jquery route with an onChange=this.form.submit() appended to construction. Anyone know whats going on/how to fix this? To me it seem like the form is submitting without processing the data.
Also I'm using: https://github.com/ghinda/css-toggle-switch for the checkbox
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>