Welcome to the nuBuilder Forums!
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Questions related to customising nuBuilder Forte with JavaScript or PHP.
vario
Posts: 154 Joined: Mon Dec 05, 2011 12:23 pm
Location: Newton Abbot, UK
Has thanked: 2 times
Been thanked: 1 time
Unread post
by vario » Sat Nov 05, 2022 2:59 pm
Code: Select all
<div id="#uppy_div#"></div>
<script>
nuInitUppy();
function nuInitUppy() {
const $objId= $('#' + '#this_object_id#');
const target = '#' + '#uppy_div#';
let uppy = new Uppy.Core();
uppy.use(Uppy.Dashboard, {
inline: true
, bundle: true
, height: $objId.cssNumber('height')
, width: $objId.cssNumber('width')
, target: target
, showProgressDetails: true
, replaceTargetContent: true
, method: 'post'
})
.use(Uppy.XHRUpload, {
endpoint: 'core/nuapi.php'
})
uppy.setMeta({ procedure: 'php_UploadFuelTransactions', cprid: document.getElementById('cpr_id').value, session_id: window.nuSESSION })
uppy.on('complete', (result) => {
if (window.nuOnFileUploadComplete) {
nuOnFileUploadComplete('FS', $objId.attr('id'), result);
}
})
}
</script>
The field cpr_id is a Select object, and in the PHP I've just got the POST variables assigned as you suggest (this is the part that had stumped me):
Code: Select all
$cprid = isset($_POST["cprid"]) ? $_POST["cprid"] : '';
Neil.
kev1n
nuBuilder Team
Posts: 4564 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 529 times
Contact:
Unread post
by kev1n » Sun Nov 06, 2022 7:33 am
If you output the $cprid variable with nuDebug($cprid), will you see an empty string in nuDebug Results?
vario
Posts: 154 Joined: Mon Dec 05, 2011 12:23 pm
Location: Newton Abbot, UK
Has thanked: 2 times
Been thanked: 1 time
Unread post
by vario » Sun Nov 06, 2022 10:06 am
Yes. If I concatenate with another character (e.g period) as
I get
in deb_message..
kev1n
nuBuilder Team
Posts: 4564 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 529 times
Contact:
Unread post
by kev1n » Sun Nov 06, 2022 7:51 pm
Replace
Code: Select all
uppy.setMeta({ procedure: 'php_UploadFuelTransactions', cprid: document.getElementById('cpr_id').value, session_id: window.nuSESSION })
With
Code: Select all
uppy.on('file-added', (file) =>{
uppy.setMeta({ procedure: 'php_UploadFuelTransactions', cprid: nuGetValue('cpr_id'), session_id: window.nuSESSION })
});
vario
Posts: 154 Joined: Mon Dec 05, 2011 12:23 pm
Location: Newton Abbot, UK
Has thanked: 2 times
Been thanked: 1 time
Unread post
by vario » Sat Nov 19, 2022 3:41 pm
As Uppy is new to me and a little above my Javascript skill level, I worked around the problem by moving the upload to a form where I can use #RECORD_ID# instead of the select object! Thanks anyway and I'll try this sometime.
P.S Not strictly relevant but I don't understand why the Uppy "catch" has "\Throwable $th"? I can't get usable error messages back to the form (e.g when I load an invalid file type) and why the backslash?
miditt
Posts: 3 Joined: Thu Dec 30, 2021 11:49 am
Unread post
by miditt » Mon Nov 28, 2022 5:51 pm
Try this:
nuSetProperty('cprid', $('#cpr_id').val(), true) ;
uppy.setMeta({ procedure: 'your_procedure_name', cprid: '#cprid#' })
yvesf
Posts: 347 Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 94 times
Been thanked: 12 times
Unread post
by yvesf » Fri Dec 30, 2022 3:54 am
Hello,
I have modified my Uppy procedure and the upload on the server works like a charm. I would like to retrieve the names of the files uploaded. I see those on the server. When I attach, I have their names, I upload, see those coming on the root document server but once done, their names have disappeared. How can I retrieve the names in order to construct the url to the file. Anyone has got an idea ? Many thanks for your help.
Yves
kev1n
nuBuilder Team
Posts: 4564 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 529 times
Contact:
Unread post
by kev1n » Fri Dec 30, 2022 9:51 am
Hi,
Do you need to retrieve the file names on server side (PHP) oder client side (JS) ?
yvesf
Posts: 347 Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 94 times
Been thanked: 12 times
Unread post
by yvesf » Fri Dec 30, 2022 11:47 am
I need to retrieve the file names on the client side .