Koha/koha-tmpl/intranet-tmpl/prog/js/form-submit.js
Jonathan Druart dee0ed4ede
Bug 36246: Add the confirmation text directly to the attribute
To avoid the eval and have all the values together.

For discussion.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
2024-05-03 18:02:13 +02:00

34 lines
1 KiB
JavaScript

$(document).ready(function(){
$('.submit-form-link').click(function(e){
e.preventDefault();
let form_data = $(this).data();
let confirm_msg = form_data.confirmationMsg;
let confirmation = 1;
if( confirm_msg ){
delete form_data.confirmationMsg;
confirmation = confirm( confirm_msg );
}
if( !confirmation ){ return false }
let the_form = $('<form/>');
if( form_data.method === 'post' ){
form_data.csrf_token = $('meta[name="csrf-token"]').attr('content');
}
the_form.attr('method', form_data.method);
the_form.attr('action', form_data.action);
delete form_data.method;
delete form_data.action;
$.each( form_data, function( key, value){
the_form.append( $('<input/>',{
type: "hidden",
name: key,
value: value,
})
);
});
$('body').append( the_form );
the_form.submit();
});
});