Log in

View Full Version : adding another function to the form



Giotto3
01-25-2009, 08:48 PM
I am very new to php, so, any help is much appreciated.

I have a simple contact form. I would like to add one function to it.
If the radio button (mailing list) is checked "YES" is it possible to open another url after submitting the form?

here is the link to the form:
http://www.knitsandpieces.com/contact_TEST.htm

and here is the php code:

<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@YourCompany.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.knitsandpieces.com/thankyou.htm" );}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
}
}
?>

Nile
01-25-2009, 08:54 PM
Do you mean if its checked, don't send the mail, direct to blah.com?
If so, add:

if(isset($_POST['check_name'])){
header("Location: blah.com");
}

Giotto3
01-25-2009, 08:57 PM
Not quite. I mean, send the e-mail and then go to another place (another url).

Nile
01-25-2009, 09:02 PM
Here:


if($send)
{header( "Location: http://www.knitsandpieces.com/thankyou.htm" );}

It looks like your directing them, do you want it to be: If its checked, instead of redirecting to: http://www.knitsandpieces.com/thankyou.htm, redirect to: http://www.knitsandpieces.com/thankyou1.htm?

Giotto3
01-25-2009, 09:08 PM
Yes, this will work too. If checked I want them to go to thankyou1, if not to thankyou2.
How should I do it?

Thank you very much!

Nile
01-25-2009, 09:15 PM
Change:


if($send)
{header( "Location: http://www.knitsandpieces.com/thankyou.htm" );}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }

With:


if($send)
if(isset($_POST['check'])){
$direct_to = 'thanks1';
} else {
$direct_to = 'thanks';
}
{header( "Location: ".$direct_to );}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }

Giotto3
01-25-2009, 09:58 PM
I inserted the new code, but it is not working. I am sorry, I guess, I am doing something wrong here. Could you, please, check. And thank you for your patience - I am very new to this.


if($send)
if(isset($_POST['check'])){
$direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
} else {
$direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
}
{header( "Location: ".$direct_to );}
else
{print "We encountered an error sending your mail, please notify info@dekko2.com"; }
}
}
?>

Nile
01-25-2009, 10:29 PM
Make sure that you have a checkbox with the name of 'check' or change the highlighted below to the name it should be:


if ($send) {
if (isset($_POST['check'])) {
$direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
} else {
$direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
}
{
header("Location: " . $direct_to);
} else {
print "We encountered an error sending your mail, please notify info@dekko2.com";
}
}
}
?>

Giotto3
01-25-2009, 10:50 PM
Sorry:

it is giving me the error:

Parse error: syntax error, unexpected T_ELSE in /var/www/html/kn/knitsandpieces.com/contact.php on line 34

Nile
01-25-2009, 10:54 PM
Sorry, since you put in the '}' I thought I needed it, here:


<?php
if ($send) {
if (isset($_POST['check'])) {
$direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
} else {
$direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
}
{
header("Location: " . $direct_to);
} else {
print "We encountered an error sending your mail, please notify info@dekko2.com";
}
}
?>

Giotto3
01-25-2009, 11:03 PM
Could you, please, check once again. Here is the whole script:
I saved it as contact.php

Something is wrong?

<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"List"} = "Mailing List";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@YourCompany.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);

if ($send) {
if (isset($_POST['check'])) {
$direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
} else {
$direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
}
{
header("Location: " . $direct_to);
} else {
print "We encountered an error sending your mail, please notify info@dekko2.com";
}
}
?>

Nile
01-25-2009, 11:32 PM
Change:


if ($send) {
if (isset($_POST['check'])) {
$direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
} else {
$direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
}
{
header("Location: " . $direct_to);
} else {
print "We encountered an error sending your mail, please notify info@dekko2.com";
}
}

To:


if ($send) {
if (isset($_POST['check'])) {
$direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
} else {
$direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
}
header("Location: " . $direct_to);
} else {
print "We encountered an error sending your mail, please notify info@dekko2.com";
}
}


My bad.

Giotto3
01-26-2009, 12:57 AM
Thank you for all your help!
Actually, it still gave me the error message when I did syntax check of the file, but I added one more curly thing { at the very end and it WORKS now!

Again, oodles of thanks!

if ($send) {
if (isset($_POST['check'])) {
$direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
} else {
$direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
}
header("Location: " . $direct_to);
} else {
print "We encountered an error sending your mail, please notify info@dekko2.com";
}
}
} (I added this one)

Nile
01-26-2009, 01:01 AM
Ok, great. Your welcome - and I'm glad to help you. (This is why I had the } at the way bottom, but it then gave you an error)