An alternative approach is to display a progress message within the form page.
The following solution will show a message in the page when the submit button is clicked and 'grey out' the rest of the page content. This prevents users from clicking on submit or browsing away while the content uploads. As it all happens in the page there is no need to remove the message when the response page loads.
I've based this version on a standard Javascript library called JQuery, and a plugin to JQuery called SimpleModal by Eric Martin. Using a library means the core functionality is well maintained with regular upgrades for new browsers. You can see the kind of effect involved at the SimpleModal demo page.
Still interested?
OK, lets go through the steps to add the progress indicator to your form:
Step 1
Download the files for the 'Basic Modal Dialog' from SimpleModal demo page. Un-zip the files and upload the 2 javascript files:to a javascript folder your server - I've named mine 'js'.
- jquery.pack.js
- jquery.simplemodal.pack.js
Step 2
Add the following script tags to the head of your form page. These should point to the javasript files you just uploaded.
Step 3HTML Code:<script src='js/jquery.pack.js' type='text/javascript'></script> <script src='js/jquery.simplemodal.pack.js' type='text/javascript'></script>
Add the following stylesheets and javascript to the head of your form page (after the script tags). You can put the styles in external files if you prefer, or they can be added to your site stylesheet.
Step 4HTML Code:<script type='text/javascript'> $(document).ready(function () { $('form input[type="submit"]').click(function (e) { $('#progress-message', { close: false }).modal(); /*e.preventDefault();*/ // uncomment for testing - stops the submission! }); }); </script> <style type="text/css" media="screen"> #modalOverlay { height:100%; width:100%; position:fixed; left:0; top:0; z-index:3000; background-color:#000; cursor:wait; } #modalContainer { height:140px; width:160px; position:fixed; left:50%; top:25%; margin-left:-80px; z-index:1000; background-color:#fff; border:3px solid #666; } #modalContainer #progress-message { padding:10px; text-align:center; color:#666; } </style> <!--[if lt IE 7]> <style type="text/css" media="screen"> #modalContainer { position: absolute; top:expression((document.documentElement.scrollTop || document.body.scrollTop) + Math.round(25 * (document.documentElement.offsetHeight || document.body.clientHeight) / 100) + 'px'); } #modalIframe { z-index:1000; position:absolute; width:100%; height:100%; top:0; left:0; } </style> <![endif]-->
Add the the progress message to the bottom of your form page. This will be hidden until the form is submitted.
You can customise the message and use your own loading animation. This example uses an animated 'spinning beach ball' graphic provided with the lightbox script by Lokesh Dhakar (See the image at the lightbox site).HTML Code:<div id="progress-message" style="display:none"> <p>Please wait while uploading...</p> <img src="img/loading_ball.gif" width="32" height="32" alt=""> </div>
Note: There is no need to modify the actual form html. The script will look for a form submit button and tell it to display the indicator when it is clicked.
Finished
The progress indicator should display whenever the form is submitted and disappear when the response page loads. You can alter the content and style of the indicator to suit your site design - nicer text box, progress animation bar etc.
Hope you find it useful.
John.


Reply With Quote
.
. To test for multiple fields you will want to start with isValid true and change it to false if any fields fail...
Bookmarks