/    Sign up×
Community /Pin to ProfileBookmark

I would like to know how to complete one of two things. Either have a submit button work with two .php files. Or how to combine the following:

[code=php]
<?PHP
$to = “[email protected]”;
$subject = “From form”;
$headers = “From: Form Mailer”;
$forward = 1;
$location = “random.com”;

$date = date (“l, F jS, Y”);
$time = date (“h:i A”);

$msg = “Below is the result of a request from random.com. It was submitted on $date at $time.nn”;

if ($_SERVER[‘REQUEST_METHOD’] == “POST”) {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}

mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header (“Location:$location”);
}
else {
echo “Thank you for submitting your request!”;
}

?>
[/code]

with the following:

[code=php]<?php

$uploaddir = “uploads”;
if(is_uploaded_file($_FILES[‘file’][‘tmp_name’]))
{
move_uploaded_file($_FILES[‘file’][‘tmp_name’],$uploaddir.’/’.$_FILES[‘file’][‘name’]);
}
print “Upload Completed!”;
?>[/code]

any help would be greatly apperciated.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 20.2006 — Off hand, I can't see any reason why you couldn't just cut-and-paste the code from one into the other.
Copy linkTweet thisAlerts:
@MYShvartsmanauthorFeb 20.2006 — I attempted that but what ended up happening is it would send me an e-mail from the "file" field it would send: C:/documents.... etc ?
Copy linkTweet thisAlerts:
@MYShvartsmanauthorFeb 20.2006 — This is my attempt at combining the code. PHP is not something I am strong in so be nice ?

[CODE]
<?php
$uploaddir = "uploads";
$to = "[email protected]";
$subject = "Custom USB Request from form";
$headers = "From: Form Mailer";
$forward = 1;
$location = "http://exile.atherra.net/Upload Test/";

$date = date ("l, F jS, Y");
$time = date ("h:i A");

$msg = "Below is the result of a request from Atherra. It was submitted on $date at $time.nn";

if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}

if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}

mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting your request!";
}

?>
[/CODE]


Results in an e-mail of:

Name : test

EMail : test

Phone : test

Style : NY Style

Quantity : TEST

Comments : test

File : C:Documents and Settings...Chart.jpg

Submit : Submit

This is the page where I'm testing this http://exile.atherra.net/Upload%20Test/
Copy linkTweet thisAlerts:
@Mester_PedizFeb 20.2006 — Dunno if i'm missing something... but what exactly are you trying to do?

Upload a file and send a mail about it has been uploaded?! or do you just want a mail and upload possibillity in the same .php doc? (coulden't see the reason for the last but....)

Cuz if you want the two things to work seperatly, then all you need to do is put them into a switch() statement, then you can change between them.

I would though still advice that you keep it in two seperate files to avoid too many problems
Copy linkTweet thisAlerts:
@ShrineDesignsFeb 20.2006 — do you mean have the one php script server the html form and parse the form data

it can be easy or very difficult depending on steps are involved (handling multiple forms)

example (probably not the best example lol)[code=php]<?php
$error = array();
$done = false;

if($_POST)
{
// process post data...
if(!isset($_POST['foo']) && $_POST['foo'] != 'bar')
{
$error[] = 'foo is not bar';
}
if(empty($error))
{
$done = true;
}
else
{
$error = implode("<br>n", $error);
$done = false;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html401/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
</head>
<body>
<?php if(!$done){
if(!empty($error)){ ?>
<div><?php echo $error; ?></div>
<?php } ?>
<form action="" method="post">
<div><input name="foo" type="text" value="bar"></div>
<div><button type="submit">Submit</button></div>
</form>
<?php }else{ ?>
<p>done!</p>
<?php } ?>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@MYShvartsmanauthorFeb 20.2006 — What I want to do is when the Customer clicks the submit button for it to upload the file they selected to a folder on the server (which is what the upload.php file does), and send the rest of the form to my e-mail (which is what the mailer.php does).. (in this case the folder is "http://exile.atherra.net/Upload%20Test/uploads")
Copy linkTweet thisAlerts:
@MYShvartsmanauthorFeb 21.2006 — anyone have any ideas?
×

Success!

Help @MYShvartsman 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 6.15,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...