I have a form event that is supposed to display a file upload and insert a row into my database. The problem that I'm having is that when I click on Upload or Cancel, the page resubmits which reloads the entire page, effectively canceling out the file upload operation.
This is the code that is triggered when you click on the upload button:
var opts = new UploadOptions();
opts.directory=uploadDir;
opts.maxFileSize="2M";
form.uploadFileFromBrowser(opts);
File upload resubmits form when clicking on Upload or Cancel
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 649
- Joined: Mon Dec 09, 2013 6:37 pm
-
- Moderator
- Posts: 184
- Joined: Tue Sep 11, 2007 8:58 am
Clicking Upload will upload the selected file from the client machine to the specified folder on the server.
Clicking Cancel will cancel the upload as expected.
In both cases the upload dialog returns back to your form.
Following a successful upload, 2 system variables are populated which you can use in your script:
$FILE_NAME contains the full path of the uploaded file as saved on the server. This will have a suffix (2,3 etc) if a file by the same name exists in the upload folder.
$FILE_NAME_USER contains the last portion of the file name on the client system.
So use either of these, as:
Both of these will contain null if the upload is cancelled.
See ufs/doc/working_with_files.htm for more details.
Clicking Cancel will cancel the upload as expected.
In both cases the upload dialog returns back to your form.
Following a successful upload, 2 system variables are populated which you can use in your script:
$FILE_NAME contains the full path of the uploaded file as saved on the server. This will have a suffix (2,3 etc) if a file by the same name exists in the upload folder.
$FILE_NAME_USER contains the last portion of the file name on the client system.
So use either of these, as:
Code: Select all
fields.UPLOADEDFILE.value = system.variables.$FILE_NAME.value;
or
fields.UPLOADEDFILE.value = system.getVariables().$FILE_NAME.value;
See ufs/doc/working_with_files.htm for more details.
0 x
-
- Ebase User
- Posts: 649
- Joined: Mon Dec 09, 2013 6:37 pm
Hovik,
That is not my issue. When I click on either the Upload or Cancel button, those 2 buttons have a type of submit.
So while the focus does return back to the form, it reloads the form as if it is being initially loaded which cancels out the server side script that initiated the file upload.
This is a problem since after the upload finishes I need to insert a row into my database to tie the upload with a specific database row.
For now, I work around this by have the upload performed in a separate form window so it won't interfere with my attachments form.
That is not my issue. When I click on either the Upload or Cancel button, those 2 buttons have a type of submit.
So while the focus does return back to the form, it reloads the form as if it is being initially loaded which cancels out the server side script that initiated the file upload.
This is a problem since after the upload finishes I need to insert a row into my database to tie the upload with a specific database row.
For now, I work around this by have the upload performed in a separate form window so it won't interfere with my attachments form.
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
What do you see in the execution log when you run the form in the designer? You should see something like this:
17:25:13.835 Info : Running On Click event for Control BUTTON1
17:25:13.835 Info : Executing Javascript script UPLOAD1A
17:25:13.850 Info : -- Suspending execution of form UPLOAD1
17:25:36.645 Info : --> User input received on page PAGE_1
17:25:36.645 Info : -- Resuming execution of form UPLOAD1
17:25:36.645 Info : Resuming On Click event for Control BUTTON1
17:25:36.645 Info : Resuming Javascript script UPLOAD1A
17:25:36.651 Info : <-- Displaying page PAGE_1
The "Resuming" messages are quite important - they are issued after the upload, as the system tries to carry on with the execution of your script after the form.uploadFileFromBrowser(opts) line.
Regards
Jon
17:25:13.835 Info : Running On Click event for Control BUTTON1
17:25:13.835 Info : Executing Javascript script UPLOAD1A
17:25:13.850 Info : -- Suspending execution of form UPLOAD1
17:25:36.645 Info : --> User input received on page PAGE_1
17:25:36.645 Info : -- Resuming execution of form UPLOAD1
17:25:36.645 Info : Resuming On Click event for Control BUTTON1
17:25:36.645 Info : Resuming Javascript script UPLOAD1A
17:25:36.651 Info : <-- Displaying page PAGE_1
The "Resuming" messages are quite important - they are issued after the upload, as the system tries to carry on with the execution of your script after the form.uploadFileFromBrowser(opts) line.
Regards
Jon
0 x
Who is online
Users browsing this forum: No registered users and 22 guests