Parse form field?

M

Mags

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!
 
G

Grant Wagner

Mags said:
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 <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_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-developer/upgrade_2.html
 
M

Mags

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!
 
T

Thomas 'PointedEars' Lahn

Mags said:
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:


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top