• I am using wfu in an admin page to upload files. The page is generated on-the-fly and the upload is triggered in javascripts with the code fragment:

    var elem = document.getElementById(“upload_1”);
    if (typeof elem.onclick == “function”) { elem.onclick.apply(elem); }

    on the input object (id=”upload_1″)that is the submit button. The upload works, but how do I test for failure in javascript?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author nickboss

    (@nickboss)

    You can implement wfu_after_upload filter. This filter runs after upload has finished. In this filter you can check if the file has succeeded or not. The filter outputs Javascript code. So, you can execute custom javascript code depending on the result.

    You can get instructions on how to use the filter in this link: https://www.iptanus.com/filters-and-actions-of-wordpress-file-upload-plugin/. Please note that you need to implement wfu_after_upload filter, not wfu_after_file_upload.

    Nickolas

    Thread Starter jlarysz

    (@jlarysz)

    Thanks. I will try this.

    Thread Starter jlarysz

    (@jlarysz)

    I’m still struggling; I think it’s ignorance. I have installed the filter mentioned above, but I can’t figure out how to get to the data in $changed_data returned by the filter.

    The first wfu form is instantiated with this code:

    <?php echo do_shortcode('[wordpress_file_upload uploadid=1 uploadpath="uploads/ASNYjournals" uploadtitle="Locate Journal in PDF Format" uploadpatterns="*.pdf, *.PDF" userdata="true" userdatalabel="Media Date in YYY-MM-DD format|t:text|s:left|r:1|a:0|p:inline|d:/Media Title|t:text|s:left|r:1|a:0|p:right|d:" ]'); ?>

    The submit button set up by this code has id=upload_1, so the upload is triggered with this:

    var elem = document.getElementById("upload_1");
    	   if (typeof elem.onclick == "function") { ret = elem.onclick.apply(elem); console.log(ret);}

    The return object “ret” does not exists, no matter what I try. This is driving me nuts!

    • This reply was modified 8 years, 1 month ago by jlarysz.
    Plugin Author nickboss

    (@nickboss)

    As an initial check to verify that the filter works put the following code in your functions.php file (or any other way you use to implement filters):

    
    if (!function_exists('wfu_after_upload_handler')) {
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    		$changable_data['js_script'] = 'console.log("check");';
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }
    

    This will generate a “check” message in your browser’s console after upload (either successful or not). If it works, then I will tell you how to check for successful file upload.

    Nickolas

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Detect upload status in javascript’ is closed to new replies.