I'm trying to save the values of a range slider in the admin of wordpress (with Advanced Custom fields). So far I am receiving the values trough ajax and I can post them with php. Now I want to be able to save them as soon as you push the Update button. The documentation of the range slider is: http://ghusse.github.io/jQRangeSlider/documentation.html This is my code so far:
$("#slider").bind("valuesChanged", function (e, data) {
$.ajax({
type: "POST",
dataType: "text",
url: "../wp-content/themes/twentytwelve/fields/number_range-v4.php",
data: { minValue: data.values.min, maxValue: data.values.max },
async: false,
success: function(data){
}
});
});
</script>
So far so good, it recieves the right values. Then in php, I'm not sure how to do this..:
<?php
$value = $_POST['minValue'];
}
function update_value( $value, $post_id, $field )
{
?>
<script type="text/javascript">$("#slider").editRangeSlider("values", "$value", "$value");</script>
<?php
$value = str_replace(',', '', $value);
// convert to float. This removes any chars
$value = floatval( $value );
// convert back to string. This alows decimals to save
$value = (string) $value;
return $value;
}
So I'm trying to save the $value variables to the database along with the post ID. It does not only save the values but also send them back to the slider, so it will be in the right position when a user edits a post. Now I'm not sure how to do this. Any suggestions?