/    Sign up×
Community /Pin to ProfileBookmark

passing filefield between 2 forms

I have two forms that I want to pass the filefield from one form to the other.

The HTML code is as follows:

<html>
<head>
<script>
function CheckForm
{document.pay.photo.value = document.ad.photo.value;
return true;
}
</script>
</head>
<body>
<h1>Upload File</h1>
<form name=”ad” action=”../../cgi-bin/upload.cgi” method=”post” enctype=”multipart/form-data”>
<p>Choose file to upload<input type=”file” name=”photo”>
<p><input type=”submit” value=”Click Here to Upload File Ad”>
</form>
<form name=”pay” action=”../../cgi-bin/upload.cgi” method=”post” enctype=”multipart/form-data”>
<input type=”hidden” value=”photo”>
<p><input type=”submit” value=”Click Here to Upload File Pay “onSubmit=”return CheckForm()”>
</form>
</body>
</html>

And then it calls the following perl script:

#!/usr/bin/perl -w
use CGI;

$query = new CGI;

$upload_dir = “../www/upload/pictures”;
$filename = $query->param(“photo”);
$filename =~ s/.*[/](.*)/$1/;
$_ = $filename;
s/[s|`|~|@|#|$|%|^|&|*|(|)|+|=|{|}|[|]|:|;|”|’|<|>|,|?||/]//g;
$filename = $_
;
$email_address = $query->param(“email_address”);

$uploadfilename = $upload_dir.”/”.$filename;

$upload_filehandle = $query->upload(“photo”);

open UPLOADFILE, “>$uploadfilename”;

while (<$upload_filehandle>)
{
print UPLOADFILE;
}

close UPLOADFILE;

print $query->header ( );

print <<“ENDOFHTML”;
<HEAD>
<TITLE>Thanks</TITLE>
</HEAD>
<BODY>
<P>Thanks for uploading your photo
<P>Your photo:
<img src=”../upload/pictures/$filename” border=”0″>
</BODY>
</HTML>
ENDOFHTML
exit;

When I hit the submit button for the “ad” form it uploads the file correctly, but when I hit the submit button for the “pay” form it fails.

How do I successfully assign a filetype element to the hidden element of the other form?

The html is located in [url]http://www.fruit-tree.com/upload/upload1.html[/url]

Thanks,

Marc

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 14.2005 — I don't think you can, it's a security issue.
Copy linkTweet thisAlerts:
@marc557authorMay 14.2005 — Then the question is:

Can I have two onSubmits for the same form, depending which submit button I click?

Thanks,

Marc
Copy linkTweet thisAlerts:
@FangMay 14.2005 — Should be possible.
Copy linkTweet thisAlerts:
@CharlesMay 14.2005 — You only get one "onsubmit" but you could find a way to fugure out just which button was pressed. You might need to add to each button an "onclick" handler to set a global variable - or what passes for a global variable in JavaScript.
Copy linkTweet thisAlerts:
@marc557authorMay 14.2005 — Charles,

Could you please be more specific on how to set the global variable on a onclick?

Thanks,

Marcos
Copy linkTweet thisAlerts:
@BigMoosieMay 14.2005 — onclick="gobalVariable=true;" in your second submit button
×

Success!

Help @marc557 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...