views:

175

answers:

2

I have a upload file form, when you hit Submit it send the file to my server, but it takes a while, in the mean time i need to tell the user wait in order to get the file uploaded, because he can press Submit again because there is no menssage to prevent him.

So, the user fill a few fields in the form, including a file. When he Send the form it sends the variables via POST to the same page:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">

A php script detect the page now have POST variables a do something. In the time between the send action and the page reload i need to display a mensage, how can i do that??? Thanks


It will be nice if you now how to trigger that with colorbox. I know how to use it from a link but no from this POST action.

A: 

Im not sure about colorbox. But you can just write a little bit of JavaScript to display a message when the form is submitted.

You can also disable the submit button when the form is submitted to prevent the user from clicking it again by using JavaScript to set onclick to "this.disabled=true"

Josh Curren
A: 
<script type="text/javascript">
    function onSubmit() {
        // do something, maybe you would want to disable the submit button too
    }
</script>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" 
      enctype="multipart/form-data"
      method="post"
      onsubmit="onSubmit()">

UPDATE: Just noticed that you are using jQuery. You can add the following script block instead:

<script type="text/javascript">
    $(function() {
        $('form').submit(function() {
            $(':submit').attr('disabled', 'disabled');
            // trigger the colorbox thing here
        });
    });
</script>
Amry
adding the "onsubmit="onSubmit()" too?
DomingoSL
@DomingoSL: No need. The first code block and the second one were meant to be two different separate solutions that do not depend on each other.
Amry