Parse form field?

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

    Parse form field?

    Hi everyone,

    Not a programmer, just need a little help.... I have a form with a
    type="file" field, which uploads the file to the server (using
    ColdFusion).

    is there a way to parse the type="file" field to extract the file name
    and store it into a DB when the form gets submitted?

    Any help is appreciated. Thx!
  • Grant Wagner

    #2
    Re: Parse form field?

    Mags wrote:
    [color=blue]
    > Hi everyone,
    >
    > Not a programmer, just need a little help.... I have a form with a
    > type="file" field, which uploads the file to the server (using
    > ColdFusion).
    >
    > is there a way to parse the type="file" field to extract the file name
    > and store it into a DB when the form gets submitted?
    >
    > Any help is appreciated. Thx![/color]

    Yes, but you would have to use server-side technology such as Perl, PHP,
    ASP, JSP, ColdFusion, etc.

    The exact solution depends on what database and server-side technology you
    have available to you.

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    • Mags

      #3
      Re: Parse form field?

      Actually, I am using CF - but I just figured it out:

      STEP 1: grabbing the info from the 4th form element....

      <script language="JavaS cript">
      <!--
      function getValue(otherE lement){
      var path_name = (otherElement.f orm.elements[4].value);
      window.document .myForm.the_fil e.value = path_name;
      }
      // -->
      </script>

      STEP 2: hidden file where this value will be passed to...

      <form name="myForm" etc.>
      <input type="hidden" name="the_file" >

      STEP 3: the submit button pushes the value into the hidden field....

      <input type="submit" onClick="getVal ue(this);" name="Set"
      value="Submit">
      </form>

      ColdFusion then can do all the database (which by the way is MS SQL) and
      submission. No idea if this is the best way to do it but it works (after
      testing for a couple hours). Maybe the code will help someone else. Now
      I just need to run some string functions on the 4th form element to
      extract the file name...

      Thanks for responding!



      *** Sent via Devdex http://www.devdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Parse form field?

        Mags wrote:[color=blue]
        > Actually, I am using CF - but I just figured it out:
        >
        > STEP 1: grabbing the info from the 4th form element....
        >
        > <script language="JavaS cript">[/color]

        The "type" attribute is required since HTML 4 and sufficient:

        <script type="text/javascript">
        [color=blue]
        > <!--[/color]

        This is obsolete, you can/should omit it and its closing counterpart.
        [color=blue]
        > [...]function getValue(otherE lement){
        > var path_name = (otherElement.f orm.elements[4].value);
        > window.document .myForm.the_fil e.value = path_name;
        > }
        > [...]
        > <input type="submit" onClick="getVal ue(this);" name="Set"
        > value="Submit">
        > </form>
        >
        > ColdFusion then can do all the database (which by the way is MS SQL) and
        > submission. No idea if this is the best way to do it but it works (after
        > testing for a couple hours).[/color]

        It works if client-side script support is present, the DOM of the UA
        provides means to retrieve the value of an input[type="file"] element
        and if timing issues do not prevent the form from being submitted too
        early, otherwise it does not work at all.
        [color=blue]
        > Maybe the code will help someone else.[/color]

        I doubt that.
        [color=blue]
        > Now I just need to run some string functions on the 4th form element to
        > extract the file name...[/color]

        It would be

        var filename =
        document.forms["myForm"].elements[3].value.replace(/.*[\\/]/, "");

        But as you do have ColdFusion available, why do you not do the
        whole thing server-side? It would be the only reliable solution.


        PointedEars

        Comment

        Working...