468,103 Members | 1,337 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

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!
Jul 23 '05 #1
3 4494
Mags wrote:
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!


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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* 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
Jul 23 '05 #2
Actually, I am using CF - but I just figured it out:

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

<script language="JavaScript">
<!--
function getValue(otherElement){
var path_name = (otherElement.form.elements[4].value);
window.document.myForm.the_file.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="getValue(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!
Jul 23 '05 #3
Mags wrote:
Actually, I am using CF - but I just figured it out:

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

<script language="JavaScript">
The "type" attribute is required since HTML 4 and sufficient:

<script type="text/javascript">
<!--
This is obsolete, you can/should omit it and its closing counterpart.
[...]function getValue(otherElement){
var path_name = (otherElement.form.elements[4].value);
window.document.myForm.the_file.value = path_name;
}
[...]
<input type="submit" onClick="getValue(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).
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.
Maybe the code will help someone else.
I doubt that.
Now I just need to run some string functions on the 4th form element to
extract the file name...


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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Dave Kuhlman | last post: by
2 posts views Thread by News charter | last post: by
29 posts views Thread by gs | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.