I have a question regarding the jQuery Star-Rating plugin.
I have many items to rate on one page, so I have added some hidden fields to each rating form.
The problem is I cannot get these values posted.
Here’s an example:
<form method="post" id="rate" action="rate.php">
<input name="rating" type="radio" class="auto-submit-star {split:4}" value="9.75" />
<input name="rating" type="radio" class="auto-submit-star {split:4}" value="10.00" />
<input type="hidden" id="post_id" value="1" />
<input type="hidden" id="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>"/>
</form>
The plugin uses a callback like this:
<script type="text/javascript">
$(function() {
$('.auto-submit-star').rating({
callback: function(value, link) {
alert("The value selected was '" + value + "'\n\nWith this callback function I can automatically submit the form with this code:\nthis.form.submit();");
}
});
});
</script>
When a star is clicked I get the prompted message, that is all good, except I can’t figure out how to also get the post_id and ip values.
I have tried :
var values = $('#rate').serialize();
alert (values);
However it always returns Object Object, it looks like only the number gets send to the function.
Is there a way to also send the other 2 fields?
You just have to set a name attribute for these inputs: