Here is shortly what I am doing and why:
Edit: Found out, that as javascript is asynchronous language, without preventDefault (stop form submitting) setTimeout never launches and action returns true straight away.
<form method="post" name="my_form" id="my_form" enctype="multipart/form-data">
<input type="submit" name="my_submit" id="my_submit" value="Submit" />
<div id="form_loading_message" style="display:none;">
<h1>Please wait, page is loading...</h1>
</div>
</form>
$('#my_submit').click(function(event) {
$.blockUI({
message: $('#form_loading_message')
});
var form = $('#my_form');
event.preventDefault();
setTimeout(function () {
form.unbind('submit').submit();
$.unblockUI();
}, 1000);
});
If you have better idea how to do this, please, I'm open for other suggestions aswell...
As I didnt find out how to do this with javascript, I used php sleep() -function before redirecting user to another page. Naturally preventDefault needed to be removed as it blocked the submit action. This solution solves the use case for me: Just to display user a message that the page is loading.