views:

97

answers:

3

I have one form as shown below:

Page 1:

<form name = "form1" method="post" action = "page2.php">
........
</form>

Page2.php:

<?php

For loop ...
.....
end

?>

Now i want to have progress bar on page 1 so that it can show the completion progress of for loop in page2.php.

Tell me how can i do that? Please don't direct me to any progress bar i'm already using the progress but i don't know how to implement the code into it,

The following is the code i'm currently using

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.progressbar.min.js"></script> 

$(document).ready(function() { 
$("#spaceused1").progressBar(); 
}); 
HTML:

<span class="progressBar" id="spaceused1">25%</span> 

<a href="#" onclick="$('#spaceused1').progressBar(20);">20</a> 
<a href="#" onclick="$('#spaceused1').progressBar(40);">40</a> 
<a href="#" onclick="$('#spaceused1').progressBar(80);">80</a> 

It works fine when i click on the above links. But how can i show it on page1 to show the progress of for loop on page2.php?

Please help me out.

+1  A: 

If I understand your question correctly, you'll need to use Ajax to submit the form. I don't use jQuery, so I don't know how to implement the progressbar with an XMLHttpRequest.

Jonah Bron
Thanks for reply but this doesn't solve my problem
fawad
A: 

Page2.php:

<?php

for(;;) {
    //In each loop iteration, update your progress and store it in the session
    $_SESSION['myFormProgress'] = myProgressCalculation();
}

?>

And then use AJAX to poll the server, receive the current value of $_SESSION['myFormProgress'], and update your progress bar accordingly.

As Jonah Bron points out, you'll also need to submit your form to Page2.php using AJAX. Otherwise, you won't be able to continue running JavaScript on the page (to update the progress bar). When the for loop is finished (and the progress bar is full), I suspect you will want to redirect the user to a new page where the results can be seen.

Dolph
What kind of value it will send back to HTML form or javascript function?
fawad
Since you want to populate the progress bar, a percentage will suffice. `echo $_SESSION['myFormProgress']; //e.g. returns 0.27 for 27%`
Dolph
So overall you mean i'll have to use AJAX to communicate between page 1 and page 2. Page 2 will send status to page 1 on each iteration of for loop. Is this right?
fawad
More specifically, you need a "page 3" to respond to the asynchronous queries. "Page 2" communicates with "page 3" by storing the progress in the `$_SESSION`. "Page 1" requests the progress from "Page 3" asynchronously.
Dolph
Actually it is being done in drupal. Page 1 is a node but page 2 is the node.tpl.php file where i have added the for loop. It goes to other node to show the results of for loop. I hope now you can understand the exact scenario and bring some good suggestions.
fawad
A: 

this is pretty dificult to do via regular Ajax, You have to mod the server slightly as PHP Does not support it.

Theres is an extention you may be interested in that allows php to do this.

Module Page: http://pecl.php.net/package/uploadprogress/1.0.1

Examples: http://svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/

RobertPitt
The OP is *not* asking for file upload progress. The OP *is* asking for progress of a long running request.
Dolph