display loading message in php self submit form
I have any form for upload video, this worked using PHP / MySQL and submit PHP_SELF action. If upload video = TRUE I print video is success and if upload video = FALSE I print error message.
Now I need to show display loading message or loading gif animator (using jQuery) after clicking the submit button and hidding the loading message after showing the TRUE/FALSE upload message. Any way to create this?
My form:
<?PHP if (isset($_POST['submit']) && $_POST['submit'] == 'uploadvideo') { //CHECK TRUE OR FALSE ..... } if (isset($uploaded) && $uploaded == TRUE){?> <div class="successbox">success upload!!!</div> <?PHP } if (isset($uploaded) && $uploaded == FALSE) {?> <div class="errorbox">error upload!!!</div> <?PHP } ?> <form action="<?PHP echo URL . '/video.php?id=' . int($_GET['id']);?>" method="POST" enctype="multipart/form-data"> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <input type="file" size="40" name="video_file" maxlength="50"> <input type="Submit" name="submit" value="uploadvideo"> </table> </form>
Answers
The easiest an quickest solution is to add a hidden <div> element to your form containing a loading message or animated gif, and when you click the submit button you show the <div> tag using jQuery:
<form action="..." method="POST" enctype="multipart/form-data" onsubmit="$('#loading').show();"> <div id="loading" style="display:none">Uploading...</div> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <input type="file" size="40" name="video_file" maxlength="50"> <input type="Submit" name="submit" value="uploadvideo"> </table> </form>
If you want something more fancy (like an actual progress bar) you'll need to look into a flash solution (like swfupload).
Starting with PHP 5.4 you can also find the upload progress in _SESSION (more details here) but seeing as PHP 5.4 is just released, you wont find many webhosts that already have this.