tags:

views:

15

answers:

1

Hi

I have built an cakephp site that lets users upload files, all works fine but I would like to show a image saying "file uploading" or something while it is uploading. Now I know that I should use the $ajax->form helpers but I can not seem to get this to work. Can some one point me in the right direction please

form(array('type' => 'post', 'options' => array( 'model'=>'Upload', 'update'=>'post2', 'action' => 'add', 'confirm' => 'Are you sure?', 'indicator' => 'loading', 'before' => '$("#post2").html("Wait a moment")'

)

)); ?>

<fieldset>
    <legend><?php __('Add Upload');?></legend>

<?php echo $form->input('title'); ?>

<div id="formUpdate">

<?php echo $form->input('Uploaded.uploaded_file', array('type' => 'file', 'label' => 'Upload file')); ?>


</fieldset>

end('Submit');?>

<div id="post2"></div>
A: 

Ok, if you don't want to use Ajax upload solution, then it could be achieved with simple javascript. I would explain how to do with jQuery, but you can achieve with any library or pure javascript too.

So, create a hidden div containing your please wait message i.e.:

<div id="wait">File is uploading please wait</div>

Then on the submit button of your form attach following function:

function pleaseWait(){
  $('#your_form_id').hide();
  $('#wait').show();
}

This basically would hide the form and will display the wait container. Once the file has been uploaded, the page will be redirected so, you don't need to worry how to show the form again.

I've did it on my project and it was working pretty well.

Nik
Perfect, nice and simple! Thanks for your help!