0

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

2
  • Show us some of the code you already have. Commented Jul 7, 2012 at 16:13
  • 1
    Or you can try and peer into this answer for a hint at how to do what you're looking to do: stackoverflow.com/questions/7692633/… Commented Jul 7, 2012 at 16:13

3 Answers 3

1

On submit you can show an loading image with javascript. Put onclick="showLoading()" attribute into your submit button, and create a showLoading() javascript function.

Sign up to request clarification or add additional context in comments.

Comments

0

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 !

    }
}

1 Comment

There are benefits to the server side implementations, you don't always control of who calls you.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.