Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

  1.  
    Is it possible to limit the type of attachment? I would suspect some type of JavaScript could be used to check the file extension, but I'm not sure on how to go about it.
    For example, if I wanted to limit only pdf files could be uploaded, how would I do that?
    • CommentAuthordbuschho
    • CommentTimeFeb 16th 2010
     
    Hey Martin,

    Wrote this a while back, but it should still work and give you a place to start:

    --------
    Email subject: Update on Your Request
    Hello,

    You could add the following code to your custom code block for your form where the users should upload only pdfs. Note that this as written will not allow them to submit a form with no file-uploads. If that is an issue, let me know and I'll rework it.

    <script type="text/javascript">
    wFORMS.behaviors.validation.rules.isPDF= { selector: ".validate-pdf", check: 'isPDF' }
    wFORMS.behaviors.validation.messages.isPDF = "This file is not a PDF.";

    wFORMS.behaviors.validation.instance.prototype.isPDF= function(element, value) {

    if(element.value.lastIndexOf(".pdf")!=-1){
    return true;
    }else{
    return false;
    }

    }


    //This part needed .class swapped for .className
    base2.DOM.Element.addEventListener(document,'DOMContentLoaded',function(){

    base2.DOM.Element.querySelectorAll(document,'input').forEach(function(e){
    if(e.type=="file")
    {
    base2.DOM.HTMLElement(e).addClass("validate-pdf");
    };
    });

    },false);
    </script>

    -----

    Happy to help further when you know where you want to go with it.
    Drew
  2.  
    Yes, having the attachment field blank will be a problem. I need it to be either PDF or blank. Thanks. This will help out a bunch.
    • CommentAuthordbuschho
    • CommentTimeFeb 17th 2010
     
    hem ... let's try swapping:
    if(element.value.lastIndexOf(".pdf")!=-1){

    for

    if( (element.value.lastIndexOf(".pdf")!=-1) || this.isEmpty(value) ){


    http://code.google.com/p/wforms/source/browse/trunk/wforms_validation.js#467

    If that doesn't work, let me know and I'll just rewrite the thing.
  3.  
    Just tested it. Works perfectly. It would be nice as an enhancement to have this in the console to limit file types and sizes. I know the code you provided doesn't help on the file size and I'm not even sure it is even possible, but that would be a nice feature.
    • CommentAuthordbuschho
    • CommentTimeFeb 18th 2010
     
    Hello,

    Unfortunately last I checked this is impossible client side due to the Javascript limited security setup. Other than the direct file location, which I believe is supplied by the browser, javascript can't pull any info about files off your hard drive. The only way to check that sort of thing client side is java or flash, both of which introduce their own problems.

    Maybe that's changed since last I looked, but I'd be surprised.

    FA Support.