简体   繁体   中英

JQuery Pause Form Submit, Add Post Data, Then Submit

I have a form where I would like to pause the submission of the form, calculate some data and add it to the post data, for retrieval in PHP.

Does anybody know if this is possible and if so how to do it?

$(function() {
    $('#get_pdf_form').on('submit', function(e) {
        var hashed_center_ids = JSON.parse($('#hashed_center_ids').val());

        var print_data = $('.print-options:checked').map(function() {
            return this.value;
        }).get();

        // add the two variables above as post data

        $(this).submit();
    });
});

I would just create hidden form elements for each item that you are computing:

$(function() {
    $('#get_pdf_form').on('submit', function(e) {
        var hashed_center_ids = JSON.parse($('#hashed_center_ids').val());

        var print_data = $('.print-options:checked').map(function() {
            return this.value;
        }).get();

        $(this).append(
           '<input type="hidden" name="hashed_center_ids" value="'+hashed_center_ids+'" />',
           '<input type="hidden" name="print_data" value="'+print_data+'" />'
        );
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM