Output in hidden field is not sent to email.

Home Forums Quform WordPress Output in hidden field is not sent to email.

This topic is: resolved
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #14949
    iz4atkal
    Participant

    Hello,

    I modified the code below using my basic knowledge to display a discount depending on how many days the product is being rented for:

    <div id='form-total'></div>
    <script>
    jQuery(document).ready(function ($) {

    function treatAsUTC(date) {
    var result = new Date(date);
    result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
    return result;
    }

    function daysBetween(startDate, endDate) {
    var millisecondsPerDay = 24 * 60 * 60 * 1000;

    return (treatAsUTC(endDate) - treatAsUTC(startDate)) / millisecondsPerDay;
    }

    var calculate = function () {

    var sDay = $('.iphorm_1_5-input-day').val();
    var sMonth = $('.iphorm_1_5-input-month').val();
    var sYear = $('.iphorm_1_5-input-year').val();

    var eDay = $('.iphorm_1_6-input-day').val();
    var eMonth = $('.iphorm_1_6-input-month').val();
    var eYear = $('.iphorm_1_6-input-year').val();

    if (sDay !== '' && sMonth !== '' && sYear !== '' && eDay !== '' && eMonth !== '' && eYear !== '') {
    // създавй две променливи, които съхраняват нови JS обект Date, но защо с - 1?
    var startDate = new Date(sYear, sMonth - 1, sDay);
    var endDate = new Date(eYear, eMonth - 1, eDay);

    var diff = daysBetween(startDate, endDate);
    var fee = '';
    if ( diff === 1) {
    var fee = 25;
    } else
    if ( diff === 2) {
    var fee = 50;
    }
    else
    if ( diff === 3) {
    var fee = 69;
    }
    else
    if ( diff === 4) {
    var fee = 88;
    }
    else
    if ( diff === 5) {
    var fee = 105;
    }

    $('#form-total').text('Fee: ' + fee + '€ ');
    } else {
    $('#form-total').text('');
    }

    };

    // Calculate on page load
    calculate();

    // Recalculate when these date fields are changed
    $('.iphorm_1_5-input-day, .iphorm_1_5-input-month, .iphorm_1_5-input-year, .iphorm_1_6-input-day, .iphorm_1_6-input-month, .iphorm_1_6-input-year').change(calculate);

    });
    </script>

    Everything works fine, but when the form is submitted, the administrator does not receive the hidden field, showing the total fee.

    How do I make it so it is submitted with the rest of the form elements?

    Thank you.

    #14950
    iz4atkal
    Participant

    Correction:

    It is not the hidden field that I need to be sent, but the <div id=’form-total’></div> displaying the fee.

    #14954
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #14969
    iz4atkal
    Participant

    Hello Alli,

    I have added the Hidden field, but I’m having problems passing the fee value to it.

    Could you explain further where to place the two lines of code? I’ve tried:

    – the ‘Default value’ line in the Hidden filed,
    – at the end of the if statement in the HTML field,

    I have replaced the unique ID with the one of the hidden field.

    Thank you for your time.

    #14988
    iz4atkal
    Participant

    Hello again,

    I tried the example in the Calculations tutorial without effect.

    My attempt below:


    <div id='form-total'></div>
    <script>
    jQuery(document).ready(function ($) {

    function treatAsUTC(date) {
    var result = new Date(date);
    result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
    return result;
    }

    function daysBetween(startDate, endDate) {
    var millisecondsPerDay = 24 * 60 * 60 * 1000;

    return (treatAsUTC(endDate) - treatAsUTC(startDate)) / millisecondsPerDay;
    }

    var calculate = function () {

    var sDay = $('.iphorm_1_5-input-day').val();
    var sMonth = $('.iphorm_1_5-input-month').val();
    var sYear = $('.iphorm_1_5-input-year').val();

    var eDay = $('.iphorm_1_6-input-day').val();
    var eMonth = $('.iphorm_1_6-input-month').val();
    var eYear = $('.iphorm_1_6-input-year').val();

    if (sDay !== '' && sMonth !== '' && sYear !== '' && eDay !== '' && eMonth !== '' && eYear !== '') {

    var startDate = new Date(sYear, sMonth - 1, sDay);
    var endDate = new Date(eYear, eMonth - 1, eDay);

    var diff = daysBetween(startDate, endDate);
    var fee = '';
    if ( diff === 1) {
    var fee = 25;
    } else
    if ( diff === 2) {
    var fee = 50;
    }
    else
    if ( diff === 3) {
    var fee = 69;
    }
    else
    if ( diff === 4) {
    var fee = 88;
    }
    else
    if ( diff === 5) {
    var fee = 105;
    }

    $('#form-total').text('Fee: ' + fee + '€');
    $('.iphorm_1_11').val('Fee: ' + fee + '€ ');

    } else {
    $('#form-total').text('');

    }
    };

    // Calculate on page load
    calculate();

    // Recalculate when these date fields are changed
    $('.iphorm_1_5-input-day, .iphorm_1_5-input-month, .iphorm_1_5-input-year, .iphorm_1_6-input-day, .iphorm_1_6-input-month, .iphorm_1_6-input-year').change(calculate);

    });
    </script>

    #14995
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #15024
    iz4atkal
    Participant

    Works great!

    Thank you for your support.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy