Warning ... I am not a JAVA programmer so please be kind ... thanks for any help you can provide.
Retired bit basher looking for a bit of help with a non-profit project.
The code listed below was based on an online example that I found on js fiddle dot net ref 9bhcB 1220 relating to testing total attachment sizes on a web page.
Issue: WP 3rd party FORM with several Upload Fields, generated with VFB Pro Form plugin, ends with a blank screen if the submitted form's total size of all attachments exceeds the WP/PHP Upload LIMIT ... this LIMIT is in place to ensure EMAIL LIMITS aren't exceeded. As attachments are emailed for further processing, their size in total, shouldn't exceed an 8M email limit (while this limit seems to differ between providers, it has always worked for me)
While one could use individual field Size restrictions, as some upload fields are optional, was hoping for simplicity and ease of use to do a FORM level MAX file check instead.
VFB Pro defines CLASS vfb-fieldType-file-upload for its upload fields ... using a WP page, the following hidden JQuery is included in the HTML editor ... the script is supposed to sum all of the upload field sizes (denoted by class name) anytime there is a change to any of these fields ... the result valid should be false if totalSize exceeds 8M and is supposed to pop up an error message then disable the submit button ... nothing appears to happen when attaching a file or files that exceed the limit ... the Submit button ID is vfb-field-1234 ... not sure how to debug this ... wondering if this may be due to the document ready function not being coded properly
<pre hidden="">
<script>
$("document").ready(function() {
$(".vfb-fieldType-file-upload").on('change', function() {
var totalSize = 0;
$(".vfb-fieldType-file-upload").each(function() {
console.dir(this);
for (var i = 0; i < this.files.length; i++ {
totalSize += this.files[i].size;
}
});
var valid = totalSize <= 8192000;
if (!valid)
alert('Over MAX File Size');
$("#vfb-field-1234").prop("disabled", !valid);
});
});
</script>
</pre>
In another instance where I used a jQuery with a VFB form, I used this variation of "ready" for setting up an ajax request
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
jQuery('#rslt').html(this.responseText);
Wondering if this more explicit variation of ready is required?
Without dev tools, is there a way to debug these scripts?
Possibly some way to indicate the current progress of any part of the script using a debug message of some sort?
Again thanks in advance for any assistance you can provide