We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14909
    • 8 Posts
    Hi - I’m trying to limit a file upload to just gifs or jpgs. Here is the code for the field I have:

    <input type="file" name="photo" id="photo" eform="photo::1:Please upload only a gif or jpg file:#REGEX ^([a-zA-Z].*|[1-9].*)\.(((j|J)(p|P)(g|G))|((g|G)(i|I)(f|F)))$" />

    The form validation works fine otherwise and the field is required as it should be but any file is allowed. I’ve used this expression before, tried a couple other expressions too no luck - just doesn’t seem to check the upload.

    Is there any way to do this using eform’s validation?

    Thanks,
    Jared
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      With eForm 1.4 you can restrict the types of files that are accepted by the #LIST validation rule
      <input class="field" type="file" name="attachment" eform="Attachment:file:0:Only upload of text documents are supported:#LIST pdf,txt,doc " /></p>
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 14909
        • 8 Posts
        Thanks - musta missed that in the documentation. Where was it - out of curiousity?

        Appreciate the help.

        -Jared
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          In one of the "sample" files that comes with the eForm download.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org