February 26, 2015 at 3:46 pm 37718 |
Nayem | Hi
I have created an action hook for a calculated field, which works fine. However I'm struggling to make the field conditional.
/*-- Land area in WPUF ---*/
function render_land_area_hook( $form_id, $post_id, $form_settings ) {
$value1 = '';
$value2 = '';
if ( $post_id ) {
$value1 = get_post_meta( $post_id, 'land_area', true );
}
?>
<li class="wpuf-el land_area2">
<div class="wpuf-label">
<label>Land Area</label>
</div>
<script type="text/javascript">
function calc(){
//grab the values
area_acres = document.getElementById('area_acres').value;
document.getElementById('area_m2').value = parseFloat(4046.86 * area_acres).toFixed(0);
}
function calc_rev(){
area_m2 = document.getElementById('area_m2').value;
document.getElementById('area_acres').value = parseFloat(area_m2 / 4046.86).toFixed(2);
}
</script>
<div class="wpuf-fields">
<input name="land_area_m2" id="area_m2" type="text" onblur="calc_rev()"> m<sup>2</sup> OR <input name="land_area_acres" id="area_acres" type="text" onblur="calc()"> acres
</div>
<script type="text/javascript">
wpuf_conditional_items.push({"condition_status":"yes","cond_field":["steps"],"cond_operator":["="],"cond_option":["1 Basics"],"cond_logic":"any","type":"text","name":"land_area2","form_id":"2422"});
</script>
<?php
}
add_action( 'land_area_hook', 'render_land_area_hook', 10, 3 );
// update
function update_land_area( $post_id ) {
if ( isset( $_POST['land_area_m2'] ) ) {
update_post_meta( $post_id, 'land_area', $_POST['land_area_m2'] );
}
}
add_action( 'wpuf_add_post_after_insert', 'update_land_area' );
add_action( 'wpuf_edit_post_after_update', 'update_land_area' );
What am I doing wrong?
Many thanks |
February 28, 2015 at 6:58 pm 37876 |
March 28, 2015 at 3:48 am 40135 |
March 29, 2015 at 11:46 am 40228 |