Filename for Uploading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Mills

    #1

    Filename for Uploading

    I have a form that asks the user to upload a file. I have a field on this
    form and I want to re-populate this form if it do not pass a validation
    function. All other fields let me set the VALUE. I understand that the
    "file" input type is different.

    How can I re-populate the file name in this type of field. I have tried the
    following statement but it does not work ...

    <input type="file" name="datafile2 " value="<c:out value="${param. datafile2}"
    />" size="40">

    Any ideas?




  • Hywel Jenkins

    #2
    Re: Filename for Uploading

    In article <41f56b8e$1_2@1 27.0.0.1>, tim_nospam_@bre wersmarine.com
    says...[color=blue]
    > I have a form that asks the user to upload a file. I have a field on this
    > form and I want to re-populate this form if it do not pass a validation
    > function. All other fields let me set the VALUE. I understand that the
    > "file" input type is different.
    >
    > How can I re-populate the file name in this type of field. I have tried the
    > following statement but it does not work ...
    >
    > <input type="file" name="datafile2 " value="<c:out value="${param. datafile2}"
    > />" size="40">
    >
    > Any ideas?[/color]

    Although the HTML spec. permits pre-population of the value field, most
    browsers disallow this for security reasons.

    --
    Hywel http://kibo.org.uk/
    I do not eat quiche.

    Comment

    • Grant Wagner

      #3
      Re: Filename for Uploading

      "Hywel Jenkins" <hyweljenkins@h otmail.com> wrote in message
      news:MPG.1c5f7e 9beb518bb49897b 3@news.individu al.net...[color=blue]
      > In article <41f56b8e$1_2@1 27.0.0.1>, tim_nospam_@bre wersmarine.com
      > says...[color=green]
      >> I have a form that asks the user to upload a file. I have a field on
      >> this
      >> form and I want to re-populate this form if it do not pass a
      >> validation
      >> function. All other fields let me set the VALUE. I understand that
      >> the
      >> "file" input type is different.
      >>
      >> How can I re-populate the file name in this type of field. I have
      >> tried the
      >> following statement but it does not work ...
      >>
      >> <input type="file" name="datafile2 " value="<c:out
      >> value="${param. datafile2}"
      >> />" size="40">
      >>
      >> Any ideas?[/color]
      >
      > Although the HTML spec. permits pre-population of the value field,
      > most
      > browsers disallow this for security reasons.[/color]

      Here is my suggestion:

      < if (param.datafile 2 contains a value) then >
      Selected file: <span style="font-family:monospac e;">="<c:out
      value="${param. datafile2}" /></span> (copy/paste this into the following
      input)
      < end if >
      File to be uploaded: <input type="file" name="datafile2 " size="40">

      This way, users don't have to browse for the file again, they can simply
      copy/paste the value they see into the input. It's more cumbersome than
      populating the <input ... value="...">, but that's the price you pay for
      using a browser as your UI.

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq


      Comment

      • Matthew Lock

        #4
        Re: Filename for Uploading

        Since it's not possible to repopulate a file input field I wonder
        consider dividing your form into 2 pages. The first page would take all
        the user's details except the file and perform validation on that, and
        the second page would just ask the user for the file.

        Some nice side effects of this 2 step approach is that you are not even
        bothering to receive files from user's who's data doesn't pass your
        validation. And the other is that if the file uploaded takes 2 minutes
        over a modem the user doesn't have to wait 2 minutes before finding out
        their data was invalid.

        Comment

        Working...