Support

Account

Home Forums Front-end Issues Update and fieldand display result before submit form

Helping

Update and fieldand display result before submit form

  • Hello,
    I have a form in frontend

    The code below is working well to calculate price and save it in database :

    function my_acf_update_totalprice( $post_id )
    {

    // bail early if not a reservation post
    if( get_post_type($post_id) !== ‘reservation’ ) {
    return;
    }

    $total = get_field( ‘prix_chambre_simple’, $post_id) * get_field( ‘nombre_de_chambres_simples’, $post_id );
    $value = $total;
    $field_name = “prix_total”;
    update_field($field_name, $value, $post_id);
    }
    add_action(‘acf/save_post’, ‘my_acf_update_totalprice’);

    I want to add a total_field before the submit button. How to display the total in this field before form is submitted ?

    Can you help me to do it please ?

    Thank you

  • Hi @dweb

    For something like that, you need to use JavaScript code to get the values and calculate the total. This page should give you more idea about it: http://stackoverflow.com/questions/2157252/get-total-of-all-input-values-with-jquery.

    because this is more related to JavaScript and jQuery, kindly visit their community for further support.

    I hope this helps 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Update and fieldand display result before submit form’ is closed to new replies.