Hi guys I have a form which after submitted links to a script "sendeveryone.php" this script takes quite a while to finish so I want to show a loading image while that is being done, how could I achieve this?
Thanks
Hi guys I have a form which after submitted links to a script "sendeveryone.php" this script takes quite a while to finish so I want to show a loading image while that is being done, how could I achieve this?
Thanks
You got 2 options: either ajax call the script, and than run some js on client side that shows progress or you can in php return a response and continue execution with my following snippet
/*
* basically allow a php script to return a response and continue with
* code execution, good for statistics.
* before echo anything to user call begin and after call end, than you can continue doing stuff
*/
class ScriptContinuationManager
{
/**
* this is the point where we need to give a sign to this class
* that we wanna write our response.
* @return void
*/
public function beginRespone()
{
ob_end_clean();
header("Connection: close");
ignore_user_abort(); // optional
ob_start();
}
/*
* after this function execution the response will be sent to the
* client, and code continue without client need to wait.
*/
public function endResponse()
{
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush(); // Strange behaviour, will not work
flush(); // Unless both are called !
}
}
Try a javascript solution:
This will hide the submit button and show an image in place. You need to choose a loading image yourself, you can generate one at http://ajaxload.info/ . Also you will have to give the form an ID attribute, and put it in the script.
(Make sure jQuery is included)
var formid = ''; // What is the ID of the form? (without the #)
var imgpath = ''; // What is the path to the loading image you want to display?
$(document).ready(function(event){
$('#'+ formid).submit(function(event){
$('#'+ formid +' input[type=submit]').after('<img src="'+ imgpath +'">').hide();
});
});
Edit: Also i suggest using AJAX methods, but looking at the writing style of your post i don't think you're that advanced.