Get radio value without refreshing the page
I want to create a form that will submit feedback (good / average / poor) to the mysql database without loading the page I am on. It works great, except that it doesn't recognize which value I am sending (if it is good, average or bad that was sent).
Here's my form:
<form method="post" id="radio_fb" style="margin-top:-90px;">
<p>
<input type="radio" name="radios" id="poor" value="poor" /><label for="poor">Poor</label>
<input type="radio" name="radios" id="average" value="average" checked="checked" /><label for="average">Average</label>
<input type="radio" name="radios" id="good" value="good" /><label for="good">Good</label>
<input type="hidden" name="url" value="<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];?> "/>
<input type="submit" name="submitter" value="Send" id="submit" />
</p>
</form>
And here is my jQuery:
jQuery(document).ready(function($) {
$("#radio_fb").submit(function() {
cname = this.radios.value;
curl = this.url.value;
submitter = this.submitter;
var data = {
name: cname,
url: curl
};
$.post("ajax.php", data, function() {
submitter.value="Sent";
submitter.disabled=true;
});
return false;
});
});
And here are the functions that store the value in the database:
<?php
include_once('config.php');
if ($_POST['radios'] == 'good') {
$url = $_POST['url'];
$bdd->exec('INSERT INTO feedback(id, url, avis) VALUES ("", "'. $url .'", "Good")');
} else if ($_POST['radios'] == 'average') {
$url = $_POST['url'];
$bdd->exec('INSERT INTO feedback(id, url, avis) VALUES ("", "'. $url .'", "Average")');
} else {
$url = $_POST['url'];
$bdd->exec('INSERT INTO feedback(id, url, avis) VALUES ("", "'. $url .'", "Poor")');
}
?>
Any idea how to fix this? I've looked at all the answers, but nothing seems to work: my function keeps returning the else statement (or nothing if I remove it).
+3
source to share