Jump to content

form redirect page


cosmic2006

Recommended Posts

Hi

I need a form to redirect to a url when you click on 'submit' - the redirect url all depends on which radio button you select.
The submitting of the form works perfectly, but the redirect part of it doesn't work, I keep getting 404 pages after the form has submitted. Is there something wrong with the code below?

It's taking me hours to try figure this out as although I have some knowledge of PHP I've never needed or used a php script like this before. Thanks in advance for your help [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]

Here's the code....


<?php
if (isset($_POST['yesno']))
{
$yesno=$_POST['yesno'];
if($yesno == "yes")
{
header("Location:http://www.google.com/");
exit;
}
if($yesno == "no")
{
header("Location: [a href=\"http://www.yahoo.com/");\" target=\"_blank\"]http://www.yahoo.com/");[/a]
exit;
}
if($yesno == "other")
{
header("Location: [a href=\"http://www.lycos.com/");\" target=\"_blank\"]http://www.lycos.com/");[/a]
exit;
}
}
?>

<form action="/cgi-bin/bizmail.cgi" method="POST">

<input name="yesno" type="radio" value="yes"> Google<br>
<input name="yesno" type="radio" value="no"> Yahoo<br>
<input name="yesno" type="radio" value="other"> Lycos<br><br>

<center><br><br>
<p><input type="submit" value="Submit Info"> </p>
</form>
Link to comment
Share on other sites

[code]<form action="/cgi-bin/bizmail.cgi" method="POST">[/code]
Unless your PHP script is called bizmail.cgi, the action should be set to the name of your PHP script... I'm guessing that's why you get 404 error
Link to comment
Share on other sites

Nearly there the actiion"" needed to post to it self good luck.


[code]
<?php
if (isset($_POST['yesno']))
{
$yesno=$_POST['yesno'];
if($yesno == "yes")
{
header("Location:http://www.google.com/");
exit;
}
if($yesno == "no")
{
header("Location: http://www.yahoo.com/");
exit;
}
if($yesno == "other")
{
header("Location: http://www.lycos.com/");
exit;
}
}
?>

<form action="" method="POST">

<input name="yesno" type="radio" value="yes"> Google<br>
<input name="yesno" type="radio" value="no"> Yahoo<br>
<input name="yesno" type="radio" value="other"> Lycos<br><br>

<center><br><br>
<p><input type="submit" value="Submit Info"> </p>
</form>
[/code]
Link to comment
Share on other sites

Thank you for your help.
I still don't completely understand what I should do.
The form script in the Action part was a CGI script, I am now using dodosmail.php. Can anyone tell me exactly what I should do next? in php beginners speak!
Link to comment
Share on other sites

[!--quoteo(post=373636:date=May 14 2006, 02:11 AM:name=cosmic girl)--][div class=\'quotetop\']QUOTE(cosmic girl @ May 14 2006, 02:11 AM) [snapback]373636[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thank you for your help.
I still don't completely understand what I should do.
The form script in the Action part was a CGI script, I am now using dodosmail.php. Can anyone tell me exactly what I should do next? in php beginners speak!
[/quote]

If you also want to use a mailing script your have to add it to the existing code ok.


It will be inpossable for you to redirect to a out side url and then also goto your mail script.

What are you trying to do completly?
Link to comment
Share on other sites

[!--quoteo(post=373641:date=May 13 2006, 10:31 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ May 13 2006, 10:31 PM) [snapback]373641[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If you also want to use a mailing script your have to add it to the existing code ok.
It will be inpossable for you to redirect to a out side url and then also goto your mail script.

What are you trying to do completly?
[/quote]

I would like to add that code I mentioned above so that it works with dodosmail.php (a mailform script), here is my dodosmail.php script...
(excuse the long script)...


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?
##$your_email_address="pixelstardesign@aol.com";
##############################################################################
# DodosMail Version 2.1 #
# Copyright 2001 Ying Zhang [a href=\"http://pure-essence.net/domain/contact.php\" target=\"_blank\"]http://pure-essence.net/domain/contact.php[/a] #
# Created 09/04/01 Last Modified 12/02/05 #
# Regretless.com [a href=\"http://www.regretless.com/\" target=\"_blank\"]http://www.regretless.com/[/a] #
##############################################################################
# COPYRIGHT NOTICE #
# Copyright 2001-2005 Ying Zhang. All Rights Reserved. #
# #
# DodosMail may be used and modified free of charge by anyone so long as #
# this copyright notice and the comments above remain intact. By using this #
# code you agree to indemnify Ying Zhang from any liability that #
# might arise from its use. #
# #
# Selling the code for this program without prior written consent is #
# expressly forbidden. In other words, please ask first before you try and #
# make money off of my program. #
# #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium. In all cases copyright and header must remain intact.#
##############################################################################

if(empty($_GET) && empty($_POST)) {
die('Please do not access this file directly. Visit <a href="http://regretless.com/scripts/" target="_blank">dodo\'s scripts collection</a> for more information!');
}

// Emular register_globals on
if (!ini_get('register_globals')) {
$superglobales = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobales, $_SESSION);
}
foreach ($superglobales as $superglobal) {
extract($superglobal, EXTR_SKIP);
}
}

// to prevent header injection
if (eregi("\r",$_POST['your_email_address']) || eregi("\n",$_POST['your_email_address'])){
exit;
}

// kick anyone whoever tried to inject a header in the form
foreach( $_POST as $value ){
if( strpos($value,'Content-Type:') !== FALSE ){
exit;
}
}


$fields = array_keys($_POST);

function headfunction($url) {
header ("Location: $url");
}

// protect the variable $reserved_vars
if(isset($reserved_vars)) {
unset($reserved_vars);
}
$reserved_vars = array("css_file", "background_color", "background_image", "text_color", "link_color", "visited_link_color", "active_link_color", "font_name", "font_size", "highlight_color", "required_fields", "after_url", "check_email_address", "subject", "your_email_address", "env_report", "owner_name", "autoresponse", "response_subject", "response_mail", "dodosmail_header_file", "dodosmail_footer_file");

function include_dodosmail_header($dodosmail_header_file) {
global $reserved_vars;
foreach($reserved_vars as $reserved_var) {
global $$reserved_var;
}

if(is_file($dodosmail_header_file)) {
include_once($dodosmail_header_file);
return;
} else {
echo "<html>\n";
echo "<head>\n";
echo "<title>\n";
echo "DodosMail\n";
echo "</title>\n";
if($css_file != "")
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$css_file\">\n";
echo "</head>\n";
echo "<body bgcolor=\"$background_color\" background=\"$background_image\" text=\"$text_color\" link=\"$link_color\" vlink=\"$visited_link_color\" alink=\"$active_link_color\">\n";
echo "<font face=\"$font_name\" size=\"$font_size\">\n";
}
}

function include_dodosmail_footer($dodosmail_footer_file) {
global $reserved_vars;
foreach($reserved_vars as $reserved_var) {
global $$reserved_var;
}
if(is_file($dodosmail_footer_file)) {
include_once($dodosmail_footer_file);
return;
} else {
echo "</font>\n</body>\n</html>";
}
}

function dodosmail_error_handle($msg) {
global $highlight_color;
if(isset($highlight_color)) {
$extra_begin = "<font color=\"".$highlight_color."\">";
$extra_end = "</font>";
} else {
$extra_begin = "<span class=\"DodosMailErrorHighLight\">";
$extra_end = "</span>";
}

return $extra_begin.$msg.$extra_end;
}

// checking required fields
// in case they used comma and space, replace
if(strstr($required_fields, ", ")) {
$required_fields = str_replace(", ", ",", $required_fields);
} else {
$required_fields = $required_fields;
}
$required_fields = explode(",", $required_fields);

for($i = 0; $i < count($required_fields); $i++) {
$required_var_name = $required_fields[$i];
if(empty($$required_var_name)) {
include_dodosmail_header($dodosmail_header_file);
echo "<p class=\"DodosMailError\">DodosMail Error - the required field ".dodosmail_error_handle($required_var_name)." is not filled.\n";
echo "<br /><br /><a href=\"javascript:history.back(1)\">Back</a>\n";
echo "</p>\n";
include_dodosmail_footer($dodosmail_footer_file);
exit;
}
}
if($check_email_address == "yes" && !empty($email)) {
if(!check_email($email)) {
include_dodosmail_header($dodosmail_header_file);
echo "<p class=\"DodosMailError\">DodosMail Error - the email ".dodosmail_error_handle($email)." is not valid.\n";
echo "<br /><br /><a href=\"javascript:history.back(1)\">Back</a>\n";
echo "</p>\n";
include_dodosmail_footer($dodosmail_footer_file);
exit;
}
}


for($i = 0; $i < count($fields); $i++) {
$actual_var = $fields[$i];
if(in_array($actual_var, $reserved_vars)) {
$inside_mail = $inside_mail;
} else {
if(is_array($$actual_var)) {
$inside_mail.= "$actual_var: ";
foreach($$actual_var as $actual_val) {
$inside_mail.= "$actual_val ";
}
$inside_mail.= "\n";
} else {
$actual_val = stripslashes($$actual_var);
$inside_mail.= "$actual_var: $actual_val\n";
}
}
}

// getting other information from the form
$cname = gethostbyaddr($_SERVER[REMOTE_ADDR]);
$inside_mail.=
"
-----------------------------------------------------------------------
SENDER INFO:
IP: $_SERVER[REMOTE_ADDR]
Computer Name: $cname
Browser Type: $_SERVER[HTTP_USER_AGENT]
Page Referer: $_SERVER[HTTP_REFERER]
-----------------------------------------------------------------------
Powered by DodosMail 2.0
[a href=\"http://regretless.com/scripts\" target=\"_blank\"]http://regretless.com/scripts[/a]
";






$headers .= "MIME-Version: 1.0\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: DodosMail 2.0 [a href=\"http://regretless.com/scripts/\r\n";\" target=\"_blank\"]http://regretless.com/scripts/\r\n";[/a]
$headers .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n";
//$headers .= "Date: ".date("R")."\r\n";
$headers .= "From: $name <$email>\r\n";



$success = mail($your_email_address, $subject, $inside_mail, $headers);
if($success) {
if($autoresponse == "yes") {
$response_subject = stripslashes($response_subject);
$response_mail = stripslashes($response_mail);
mail($email, $response_subject, $response_mail, "From: $owner_name <$your_email_address>");
}
if($after_url == "") {
// out put send info
include_dodosmail_header($dodosmail_header_file);


echo "<p>\n";

echo "The following email has been sent successfully!</p><ul>";
for($i = 0; $i < count($fields); $i++) {
$actual_var = $fields[$i];
if(in_array($actual_var, $reserved_vars))
echo "";
else {
if(is_array($$actual_var)) {
echo "<li>$actual_var: ";
foreach($$actual_var as $actual_val) {
echo "$actual_val ";
}
echo "</li>\n";
} else {
$actual_val = stripslashes($$actual_var);
echo "<li>$actual_var: $actual_val</li>\n";
}
}
}
echo "</ul>\n<p><a href=\"http://regretless.com/scripts/\">DodosMail</a> v2.0</p>";
include_dodosmail_footer($dodosmail_footer_file);
exit;
} else {
headfunction($after_url);
}
} else {
include_dodosmail_header($dodosmail_header_file);
echo "<p class=\"DodosMailError\">DodosMail Error - the owner the php server is experiencing techinical difficulties. Please email use ".dodosmail_error_handle($your_email_address)." to send your email.\n";
echo "<br /><br /><a href=\"javascript:history.back(1)\">Back</a>\n";
echo "</p>\n";
include_dodosmail_footer($dodosmail_footer_file);
exit;
}



function check_email($email) {
if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) ||
(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) {
return true;
}
return false;
}



?>
[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.