/    Sign up×
Community /Pin to ProfileBookmark

Hi guys,

Wondering if there’s a way to process a script on form submit but do not actually take them to the script page, instead reroute them to another regular .html page? I’m a supervisor at my place of work and would like the representatives to fill out a form if they need to email me something but they don’t have email access only I do. I can’t use PHP at work so I want to have a script on my server for my webpage and just use that to process and send the mail to myself then reroute the agent back to an html page on the local server at work, without them ever seeing the php script which is sending the mail.

Is this possible?

<form action=”http://www.mydomain.com/myscripttosendmail.php” method=”Any ideas”>

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@1cookieOct 10.2009 — Hi guys,

Wondering if there's a way to process a script on form submit but do not actually take them to the script page, instead reroute them to another regular .html page? I'm a supervisor at my place of work and would like the representatives to fill out a form if they need to email me something but they don't have email access only I do. I can't use PHP at work so I want to have a script on my server for my webpage and just use that to process and send the mail to myself then reroute the agent back to an html page on the local server at work, without them ever seeing the php script which is sending the mail.

Is this possible?

<form action="http://www.mydomain.com/myscripttosendmail.php" method="Any ideas">[/QUOTE]

Are you familiar with the[code=php]<form action=<?php echo $_SERVER['PHP_SELF'] ?> method="post">[/code]construct???
Copy linkTweet thisAlerts:
@MindzaiOct 10.2009 — I think the OP wants to post to a script on a different server, not the same script.

@OP: The method used in your code snippet would be "post" as normal. Then in the script on your other domain, after you've sent the email you can redirect back via a HTTP header:

[code=php]
// email script

// send the email here

// send them back to somewhere else
header('Location: http://www.firstdomain.com/foo.html');
exit();
[/code]


Note that you must not output anything to the browser before sending the header.

Also if you just want to chuck them back from where they came, you can check if the HTTP_REFERRER value is available in the $_SERVER superglobal and use that:

[code=php]
$redirectTo = "http://www.firstdomain.com/foo.html"; // default in case we cant tell where they came from.
if (isset($_SERVER['HTTP_REFERRER')) && !empty($_SERVER['HTTP_REFERRER')) {
$redirectTo = $_SERVER['HTTP_REFERRER');
}
header("Location: $redirectTo");
exit();
[/code]
Copy linkTweet thisAlerts:
@BalistikBillauthorOct 11.2009 — You are correct that is what I wanted to do. Is there anyway to have it when the user hits the submit button to the form that the action script will show up in a new popup? So I don't have to redirect the browser? That way I could just have the script run and close it with javascript and the user will be on the original page still. Is this possible?
Copy linkTweet thisAlerts:
@BalistikBillauthorOct 11.2009 — I basically figured it out the user really doesn't notice that they are redirected to a different page. It's pretty nice!

Here's the HTML page.
[code=php]
<html>
<head>
<script language="javascript">
window.onload = clear;
function clear(){
document.sendMailToBilly.agentName.value = "";
document.sendMailToBilly.agentID.value = "";
document.sendMailToBilly.subjectEmail.value = "";
document.sendMailToBilly.body.value = "";
}
</script>
</head>
<body>
<h1>Want to send an email to your sup?</h1></br>
Please feel out the below form.</br>
<form name="sendMailToBilly" action="http://www.domain.com/sendMail.php" method="POST">
Enter Your Name:</br>
<input type="text" name="agentName" size="40"></br></br>
Enter Your Agent ID:</br>
<input type="text" name="agentID" size="5" maxlength="5"></br></br>
Enter The Subject Of Email:</br>
<input type="text" name="subjectEmail" size="100"></br></br>
Enter The Body:</br>
<textarea name="body" rows="25" cols="100"></textarea></br>
<input type="submit" value="Send Email To Sup!">
</form>

</body>
</html>
[/code]


And Here's the PHP page.

[code=php]

<html>
<head>
<title>Sending Email....</title>
</head>
<body>
<?php

$body = "Agent Name: " . $_POST['agentName'] . "

Agent ID: " . $_POST['agentID'] . "

"
. $_POST['body'];

$subject = $_POST['emailMessage'];

mail('emailTo', $_POST['subjectEmail'], $body, "From: " . $_POST['agentName'] . "@someDomain");
?>
<script language="javascript">
history.back();
</script>
</body>
</html>
[/code]


Thanks for all your help!
Copy linkTweet thisAlerts:
@MindzaiOct 11.2009 — You should have a read up on header injection attacks as your script is currently vulnerable.
Copy linkTweet thisAlerts:
@BalistikBillauthorOct 11.2009 — How do you go about preventing this? Verifying the data that is being submitted on the form and not allowing the form to process unless all that data is valid?
×

Success!

Help @BalistikBill 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,
)...