Log in

View Full Version : PHP Contact form redirect help



chulagrl24
05-07-2009, 01:43 AM
My form works with one exception - how do I redirect the page back to the contact form - instead of the php page?

<?php
//Variables.
$user_email = $_REQUEST['email'];
$user_name = $_REQUEST['name'];
$user_subject = $_REQUEST['subject'];
$user_How= $_REQUEST['How'];
$user_comment = $_REQUEST['comment'];
$user_send = $_REQUEST['copy'];
$user_check = stripos("$user_email","@");
//Body of the email to be sent.
$body_mail = "Hello Christie, someone wants to contact you.. Details..
Name: $user_name $user_lastname
Email: $user_email
subject: $user_subject
How: $user_How
Comment: $user_comment.";
//Body of the Email for the user requesting a copy.
$body_email = "
Here is a copy of the email.
Your Name: $user_name $user_lastname.
Your Email: $user_email.
Your subject: $user_subject.
Your Comment: $user_comment.
Thank you for contacting us, we'll reply ASAP.
Yourwebsite team.";
//Check if the user submited the data require.
//If the @ is measing from the email address stop the user for continuing.
if ($user_check) {
echo "";
}
else {
echo "You can't continue with out a email address, Please enter a email address.";
exit ($user_check);
}
if (empty($user_name)) {
echo "<center><h2><font color='ff0000'>ERROR</font></h2></center>You didn't enter a your first name.<br>";
exit();
}
elseif (!$user_comment) {
echo "<center><h2><font color='ff0000'>ERROR</h2></center></font>Please enter a comment.";
die();
}
//Everything okay? send the e-mail.
else {
mail('customerservice@verysweetbabycakes.com','Email from YOURWEBITE',"$body_mail","from:YOURWEBSITE");
echo "your email was sent! Thank you.";
}
//If the checkbox if check send a copy to the user.
if (isset($user_send)) {
@mail("$user_email","The copy of your information from YOURWEBSITE","$body_email","YOURWEBSITE");
echo "And a copy of the Email was send to you!";
}
else {
die($user_send);
}
?>

<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css" media="all">
form, label, input { font-size : 1em; }
fieldset { width : 36em; padding : 0.5em 1em; }
label { float: left; position : relative; width : 15em; display : inline; margin : .5em .5em; }
label.long { width : 12em; float: left; position : relative; width : 15em; display : inline; margin : .5em .5em;}
label input { display: inline; left : 100%; top : 0px; width : 14em; }
label.long input { width : 18em; }
input.submit { margin-left : 15em; background-color: #CCCCCC; font-weight: bold; font-size: 12px; color: #C7377D; border=1px; border-color=#cc9999;}
}
br { clear: both; }
</style>
</head>
<body>

<p><center>
<form action="mail.php" method="post" name="mail">
<input name="redirect" value="success.html" type="hidden" />
<fieldset>
<legend>Contact Form</legend>
<label> Your Name:<input name="name" > </label>

<label>How did you hear about us:<br />
<select name="How">
<option value="Select One....." selected="selected">Select One</option>
<option value="Friend">Friend</option>
<option value="Yahoo">Yahoo</option>
<option value="Google">Google</option>
<option value="Other Search Engine">Other Search Engine</option>
<option value="Flyer/Ad">Flyer/Ad</option>
<option value="Other Website">Other Website</option> </select></label>

<label>Subject/Topic:<br />
<select name="subject">
<option value="Select a topic....." selected="selected">Select a topic.....</option>
<option value="Product Information">Product Information</option>
<option value="Customer Support">Customer Support</option>
<option value="Community Involvement">Community Involvement</option>
<option value="Site Technical Issue">Site Technical Issue</option>
<option value="Urgent">Urgent</option>
<option value="Other">Other</option> </select></label>


<label class="long">Email:<input name="email" /></label><br />
<label for="comments">Comments:<textarea name="comment" cols="40" rows="8">Type Comment Here </textarea></label>
<br /><input value="Submit" type="submit" class="submit" /> </fieldset> </form></center>

bluewalrus
05-07-2009, 02:55 AM
You could just make the form and the php page the same and set the values to be displayed when submitted....say your page is contact.html...make it contact.php then try the rest also add in $send = $send - 1; at any point where the form should be shown again, like if the email address is wrong. that might be the wrong order as well $send = 1 - $send;.



<?php
$send = $_POST ['sent'];
$send = send + 1;
if ($send == 0 ) {
?>
<form action="contact.php" method="post" name="mail">
<input type="hidden" value="0" name="sent" />

*****rest of form*****
<?php
} else {
//Variables.
$user_email = $_REQUEST['email'];
$user_name = $_REQUEST['name'];
$user_subject = $_REQUEST['subject'];
$user_How= $_REQUEST['How'];
$user_comment = $_REQUEST['comment'];
$user_send = $_REQUEST['copy'];
$user_check = stripos("$user_email","@");
//Body of the email to be sent.
$body_mail = "Hello Christie, someone wants to contact you.. Details..
Name: $user_name $user_lastname
Email: $user_email
subject: $user_subject
How: $user_How
Comment: $user_comment.";
//Body of the Email for the user requesting a copy.
$body_email = "
Here is a copy of the email.
Your Name: $user_name $user_lastname.
Your Email: $user_email.
Your subject: $user_subject.
Your Comment: $user_comment.
Thank you for contacting us, we'll reply ASAP.
Yourwebsite team.";
//Check if the user submited the data require.
//If the @ is measing from the email address stop the user for continuing.
if ($user_check) {
echo "";
}
else {
echo "You can't continue with out a email address, Please enter a email address.";
exit ($user_check);
}
if (empty($user_name)) {
echo "<center><h2><font color='ff0000'>ERROR</font></h2></center>You didn't enter a your first name.<br>";
exit();
}
elseif (!$user_comment) {
echo "<center><h2><font color='ff0000'>ERROR</h2></center></font>Please enter a comment.";
die();
}
//Everything okay? send the e-mail.
else {
mail('customerservice@verysweetbabycakes.com','Email from YOURWEBITE',"$body_mail","from:YOURWEBSITE");
echo "your email was sent! Thank you.";
}
//If the checkbox if check send a copy to the user.
if (isset($user_send)) {
@mail("$user_email","The copy of your information from YOURWEBSITE","$body_email","YOURWEBSITE");
echo "And a copy of the Email was send to you!";
}
else {
die($user_send);
}
}
?>

chulagrl24
05-07-2009, 05:03 PM
http://verysweetbabycakes.com/contact.php

I am not sure how to implement the $send = $send - 1; or you said it might be $send = 1- $send;

If you can look at the page and tell me what I did wrong - I would be greatly appreciated - I am still learning how all this works. I have taught myself everything I know by reading online and trial an error and help sites. This is the first time I have reached out on a forum for help. I really appreciate it.

bluewalrus
05-07-2009, 06:54 PM
Is the code the same as i posted it above? I can't view source and get the php code.

chulagrl24
05-07-2009, 08:31 PM
Here is the whole code for the page: Thank you


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css" media="all">
form, label, input { font-size : 1em; }
fieldset { width : 36em; padding : 0.5em 1em; }
label { float: left; position : relative; width : 15em; display : inline; margin : .5em .5em; }
label.long { width : 12em; float: left; position : relative; width : 15em; display : inline; margin : .5em .5em;}
label input { display: inline; left : 100%; top : 0px; width : 14em; }
label.long input { width : 18em; }
input.submit { margin-left : 15em; background-color: #CCCCCC; font-weight: bold; font-size: 12px; color: #C7377D; border=1px; border-color=#cc9999;}
}
br { clear: both; }
</style>
</head>
<body>
<div id="header">
<h1>Unique, Beautiful,
<br />Useable, Friendly
<br />Baby Gifts
</h1>

</div>
<div id="tabholder">
<div id="tabs8">
<ul>
<li><a href="index.html"><span>Home</span></a> </li>
<li><a href="meet.html"><span>Meet Us</span></a></li>
<li><a href="newitems.html"><span>New Items</span></a></li>
<li><a href="why.html"><span>Why Buy Here</span></a></li>
<li><a href="specials.html"><span>Specials</span></a></li>
<li><a href="babycycle.html"><span>Babycycle</span></a></li>
<li><a href="free.html"><span>Free Gifts</span></a></li>
<li id="current"><a href="#"><span>Contact Us</span></a></li>

</ul>
</div>
</div>

<div id="content">
<div id="left">
<h3>Baby Diaper Cakes: </h3>

<div class="navcontainer">
<ul class="navlist">
<li><a href="neutral.html">Neutral Diaper Cakes</a></li>
<li><a href="boy.html">Boy Diaper Cakes</a></li>
<li><a href="girl.html">Girl Diaper Cakes</a></li>
<li><a href="twins.html">Twins Diaper Cakes</a></li>
<li><a href="poundcakes.html">Diaper Pound Cakes</a></li>
<li><a href="cupcakes.html">Diaper Cupcakes</a></li>
</ul>
</div>


<h3>EcoFriendly Diaper Cakes: </h3>

<div class="navcontainer">
<ul class="navlist">
<li><a href="cloth.html">Cloth Diaper Cakes</a></li>
<li><a href="disposable.html">Disposable Diaper Cakes</a></li>
<li><a href="ecopoundcakes.html">Diaper Pound Cakes</a></li>
<li><a href="ecocupcakes.html">Diaper Cupcakes</a></li>
</ul>
</div>

<h3>Gifts: </h3>


<div class="navcontainer">
<ul class="navlist">
<li><a href="babybaskets.html">"New Arrival" Baskets</a></li>
<li><a href=giftbag.html">Gift Bags Sets</a></li>
<li><a href="tiny.html">Tiny Gift Sets</a></li>
</ul>
</div>

<h3>Helpful Links </h3>

<div class="navcontainer">
<ul class="navlist">
<li><a href="faq.html">Store FAQ</a></li>
<li><a href=ship.html">Shipping Info</a></li>
<li><a href="tiny.html">Tiny Gift Sets</a></li>
</ul>
</div>
<h3> </h3>
<div class="block1">
<a href="#">click here</a>
</div>
</div>
<div id="right">
<h2>Questions and More - contact us</h2>
<p>Very Sweet Baby Cakes<br>PO Box 354<br>Caldwell, ID 83605





<p><center>
<?php
$send = $_POST ['sent'];
$send = send + 1;
if ($send == 0 ) {
?>
<form action="contact.php" method="post" name="mail">
<input type="hidden" value="0" name="sent" />
<fieldset>
<legend>Contact Form</legend>
<label> Your Name:<input name="name" > $send = $send - 1;</label>

<label>How did you hear about us:<br />
<select name="How">
<option value="Select One....." selected="selected">Select One</option>
<option value="Friend">Friend</option>
<option value="Yahoo">Yahoo</option>
<option value="Google">Google</option>
<option value="Other Search Engine">Other Search Engine</option>
<option value="Flyer/Ad">Flyer/Ad</option>
<option value="Other Website">Other Website</option> </select></label>

<label>Subject/Topic:<br />
<select name="subject">
<option value="Select a topic....." selected="selected">Select a topic.....</option>
<option value="Product Information">Product Information</option>
<option value="Customer Support">Customer Support</option>
<option value="Community Involvement">Community Involvement</option>
<option value="Site Technical Issue">Site Technical Issue</option>
<option value="Urgent">Urgent</option>
<option value="Other">Other</option> </select></label>


<label class="long">Email:<input name="email" /></label><br />
<label for="comments">Comments:<textarea name="comment" cols="40" rows="8">Type Comment Here </textarea></label>
<br /><input value="Submit" type="submit" class="submit" /> </fieldset> </form></center>

<?php
} else {
//Variables.
$user_email = $_REQUEST['email'];
$user_name = $_REQUEST['name'];
$user_subject = $_REQUEST['subject'];
$user_How= $_REQUEST['How'];
$user_comment = $_REQUEST['comment'];
$user_send = $_REQUEST['copy'];
$user_check = stripos("$user_email","@");
//Body of the email to be sent.
$body_mail = "Hello Christie, someone wants to contact you.. Details..
Name: $user_name $user_lastname
Email: $user_email
subject: $user_subject
How: $user_How
Comment: $user_comment.";

//Check if the user submited the data require.
//If the @ is measing from the email address stop the user for continuing.
if ($user_check) {
echo "";
}
else {
echo "You can't continue with out a email address, Please enter a email address.";
exit ($user_check);
}
if (empty($user_name)) {
echo "<center><h2><font color='ff0000'>ERROR</font></h2></center>You didn't enter a your first name.<br>";
exit();
}
elseif (!$user_comment) {
echo "<center><h2><font color='ff0000'>ERROR</h2></center></font>Please enter a comment.";
die();
}
//Everything okay? send the e-mail.
else {
mail('customerservice@verysweetbabycakes.com','Email from verysweetbabycakes.com',"$body_mail","from:verysweetbabycakes.com");
echo "your email was sent! Thank you.";
}
//If the checkbox if check send a copy to the user.
if (isset($user_send)) {
@mail("$user_email","","$body_email","");
echo "";
}
else {
die($user_send);
}
}
?> </center>



</div>
</div>

<div id="footer">

<!-- PayPal Logo --><table border="0" cellpadding="10" cellspacing="0" align="left"><tr><td align="center"></td></tr>
<tr><td align="center"><a href="#" onclick="javascript:window.open('https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside','olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350');">
<img src="https://www.paypal.com/en_US/i/bnr/horizontal_solution_PPeCheck.gif" border="0" alt="Solution Graphics" align="left"></a></td></tr></table>
<!-- PayPal Logo --><div class="copy"><p></P><p></P>
<P>Copyright &copy; 2009 Very Sweet Baby Cakes / <a href="privacy.html">Privacy Notice</a> / <a href="http://www.touchedbyhearts.com" target=_new>touchedbyhearts.com</a> /</P></div>


</div>

</body>
</html>

bluewalrus
05-08-2009, 12:36 AM
I think this will do it...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css" media="all">
form, label, input { font-size : 1em; }
fieldset { width : 36em; padding : 0.5em 1em; }
label { float: left; position : relative; width : 15em; display : inline; margin : .5em .5em; }
label.long { width : 12em; float: left; position : relative; width : 15em; display : inline; margin : .5em .5em;}
label input { display: inline; left : 100%; top : 0px; width : 14em; }
label.long input { width : 18em; }
input.submit { margin-left : 15em; background-color: #CCCCCC; font-weight: bold; font-size: 12px; color: #C7377D; border=1px; border-color=#cc9999;}
}
br { clear: both; }
</style>
</head>
<body>
<div id="header">
<h1>Unique, Beautiful,
<br />Useable, Friendly
<br />Baby Gifts
</h1>

</div>
<div id="tabholder">
<div id="tabs8">
<ul>
<li><a href="index.html"><span>Home</span></a> </li>
<li><a href="meet.html"><span>Meet Us</span></a></li>
<li><a href="newitems.html"><span>New Items</span></a></li>
<li><a href="why.html"><span>Why Buy Here</span></a></li>
<li><a href="specials.html"><span>Specials</span></a></li>
<li><a href="babycycle.html"><span>Babycycle</span></a></li>
<li><a href="free.html"><span>Free Gifts</span></a></li>
<li id="current"><a href="#"><span>Contact Us</span></a></li>

</ul>
</div>
</div>

<div id="content">
<div id="left">
<h3>Baby Diaper Cakes: </h3>

<div class="navcontainer">
<ul class="navlist">
<li><a href="neutral.html">Neutral Diaper Cakes</a></li>
<li><a href="boy.html">Boy Diaper Cakes</a></li>
<li><a href="girl.html">Girl Diaper Cakes</a></li>
<li><a href="twins.html">Twins Diaper Cakes</a></li>
<li><a href="poundcakes.html">Diaper Pound Cakes</a></li>
<li><a href="cupcakes.html">Diaper Cupcakes</a></li>
</ul>
</div>


<h3>EcoFriendly Diaper Cakes: </h3>

<div class="navcontainer">
<ul class="navlist">
<li><a href="cloth.html">Cloth Diaper Cakes</a></li>
<li><a href="disposable.html">Disposable Diaper Cakes</a></li>
<li><a href="ecopoundcakes.html">Diaper Pound Cakes</a></li>
<li><a href="ecocupcakes.html">Diaper Cupcakes</a></li>
</ul>
</div>

<h3>Gifts: </h3>


<div class="navcontainer">
<ul class="navlist">
<li><a href="babybaskets.html">"New Arrival" Baskets</a></li>
<li><a href=giftbag.html">Gift Bags Sets</a></li>
<li><a href="tiny.html">Tiny Gift Sets</a></li>
</ul>
</div>

<h3>Helpful Links </h3>

<div class="navcontainer">
<ul class="navlist">
<li><a href="faq.html">Store FAQ</a></li>
<li><a href=ship.html">Shipping Info</a></li>
<li><a href="tiny.html">Tiny Gift Sets</a></li>
</ul>
</div>
<h3> </h3>
<div class="block1">
<a href="#">click here</a>
</div>
</div>
<div id="right">
<h2>Questions and More - contact us</h2>
<p>Very Sweet Baby Cakes<br>PO Box 354<br>Caldwell, ID 83605





<p><center>
<?php
$send = $_POST ['sent'];
$send = send + 1;
if ($send == 0 ) {
?>
<form action="contact.php" method="post" name="mail">
<input type="hidden" value="0" name="sent" />
<fieldset>
<legend>Contact Form</legend>
<label> Your Name:<input name="name" ></label>

<label>How did you hear about us:<br />
<select name="How">
<option value="Select One....." selected="selected">Select One</option>
<option value="Friend">Friend</option>
<option value="Yahoo">Yahoo</option>
<option value="Google">Google</option>
<option value="Other Search Engine">Other Search Engine</option>
<option value="Flyer/Ad">Flyer/Ad</option>
<option value="Other Website">Other Website</option> </select></label>

<label>Subject/Topic:<br />
<select name="subject">
<option value="Select a topic....." selected="selected">Select a topic.....</option>
<option value="Product Information">Product Information</option>
<option value="Customer Support">Customer Support</option>
<option value="Community Involvement">Community Involvement</option>
<option value="Site Technical Issue">Site Technical Issue</option>
<option value="Urgent">Urgent</option>
<option value="Other">Other</option> </select></label>


<label class="long">Email:<input name="email" /></label><br />
<label for="comments">Comments:<textarea name="comment" cols="40" rows="8">Type Comment Here </textarea></label>
<br /><input value="Submit" type="submit" class="submit" /> </fieldset> </form></center>

<?php
} else {
//Variables.
$user_email = $_REQUEST['email'];
$user_name = $_REQUEST['name'];
$user_subject = $_REQUEST['subject'];
$user_How= $_REQUEST['How'];
$user_comment = $_REQUEST['comment'];
$user_send = $_REQUEST['copy'];
$user_check = stripos("$user_email","@");
//Body of the email to be sent.
$body_mail = "Hello Christie, someone wants to contact you.. Details..
Name: $user_name $user_lastname
Email: $user_email
subject: $user_subject
How: $user_How
Comment: $user_comment.";

//Check if the user submited the data require.
//If the @ is measing from the email address stop the user for continuing.
if ($user_check) {
echo "";
}
else {
echo "You can't continue with out a email address, Please enter a email address.";
//exit ($user_check);
$send = $send - 1;
}
if (empty($user_name)) {
echo "<center><h2><font color='ff0000'>ERROR</font></h2></center>You didn't enter a your first name.<br>";
$send = $send - 1;
}
elseif (!$user_comment) {
echo ("<center><h2><font color='ff0000'>ERROR</h2></center></font>Please enter a comment.");
$send = $send - 1;
}
//Everything okay? send the e-mail.
else {
mail('customerservice@verysweetbabycakes.com','Email from verysweetbabycakes.com',"$body_mail","from:verysweetbabycakes.com");
echo "your email was sent! Thank you.";
}
//If the checkbox if check send a copy to the user.
if (isset($user_send)) {
@mail("$user_email","","$body_email","");
echo "";
}
else {
die($user_send);
}
}
?> </center>



</div>
</div>

<div id="footer">

<!-- PayPal Logo --><table border="0" cellpadding="10" cellspacing="0" align="left"><tr><td align="center"></td></tr>
<tr><td align="center"><a href="#" onclick="javascript:window.open('https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside','olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350');">
<img src="https://www.paypal.com/en_US/i/bnr/horizontal_solution_PPeCheck.gif" border="0" alt="Solution Graphics" align="left"></a></td></tr></table>
<!-- PayPal Logo --><div class="copy"><p></P><p></P>
<P>Copyright &copy; 2009 Very Sweet Baby Cakes / <a href="privacy.html">Privacy Notice</a> / <a href="http://www.touchedbyhearts.com" target=_new>touchedbyhearts.com</a> /</P></div>


</div>

</body>
</html>