Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
cmcraft
New Member
New Member



Joined: Dec 05, 2005
Posts: 24

PostPosted: Wed May 10, 2006 12:12 pm Reply with quote

I am using the following code to validate a little cheesy send mail form on the front of my webpage at www.christophercraft.com. What I need to know is how to delay the refresh located at the bottom so that the folks can see that the mail has been sent successfully!
Code:
echo" <scr ipt>

window.location=\"http://www.christophercraft.com\"
</scr ipt> ";
?>


Any help would be appreciated!

Yours,

Chris
 
View user's profile Send private message
hitwalker
Sells PC To Pay For Divorce



Joined:
Posts: 5661

PostPosted: Wed May 10, 2006 12:56 pm Reply with quote

this should do ...

Code:


<scr ipt>
<!--
var version = parseInt(navigator.appVersion)
if (version>=4 || window.location.replace)
setTimeout("window.location.replace('http://www.christophercraft.com')",5000);
else
window.location.href = "http://www.christophercraft.com"
// -->
</scr ipt>

 
View user's profile Send private message
cmcraft







PostPosted: Thu May 11, 2006 4:40 am Reply with quote

I ran than and got this error...

Quote:
Parse error: parse error, unexpected '<' in /home/content/html/process.php on line 73


Here is the full code, it's a totally php file called process.php

Code:


<?php
if (!isset($_POST['submit'])) {
   echo "<h1>Error</h1>\n
      <p>Accessing this page directly is not allowed.</p>";
   exit;
}

function cleanUp($data) {
   $data = trim(strip_tags(htmlspecialchars($data)));
   return $data;
}

$name      = cleanUp($_POST['name']);
$email     = cleanUp($_POST['email']);
$url       = cleanUp($_POST['url']);
$comments  = cleanUp($_POST['comments']);

if ((empty($name)) || (empty($email)) || (empty($comments))) {
   echo "<h2>Input Error</h2>\n
     <p><strong>Name</strong>, <strong>e-mail</strong> and <strong>comments</strong> are required fields. Please fill them in and try again:</p>";

   echo "<form action=\"process.php\" method=\"post\"><p>";
   echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />";
   echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />";
   echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />";
   echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />";
   echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />";
   echo "</p></form>";

   exit;
}

if (!ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$",$email)) {
echo "<h2>Input Error</h2>\n
<p>The e-mail address \"$email\" isn't valid. Please edit it and try again:</p>";

   echo "<form action=\"process.php\" method=\"post\"><p>";
   echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />";
   echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />";
   echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />";
   echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />";
   echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />";
   echo "</p></form>";

   exit;
}

$email = preg_replace("([\r\n])", "", $email);

$find = "/(content-type|bcc:|cc:)/i";
if (preg_match($find, $name) || preg_match($find, $email) || preg_match($find, $url) || preg_match($find, $comments)) {
   echo "<h1>Error</h1>\n
      <p>No meta/header injections, please.</p>";
   exit;
}

$recipient = "";
$subject   = "ChristopherCraft.com Feeedback";

$message   = "Name: $name \n";
$message  .= "E-mail: $email \n";
$message  .= "URL: $url \n";
$message  .= "Comments: $comments";

$headers   = "From: ChristopherCraft dot com \r\n";
$headers  .= "Reply-To: $email";

if (mail($recipient,$subject,$message,$headers)) {
   echo "<p>Mail sent successfully.</p>";
} else {
   echo "<p>Mail not sent this time.</p>";
}
<sc ript>
<!--
var version = parseInt(navigator.appVersion)
if (version>=4 || window.location.replace)
setTimeout("window.location.replace('http://www.christophercraft.com')",5000);
else
window.location.href = "http://www.christophercraft.com"
// -->
</scr ipt>
?>


Thanks for the help! You guys here are so incredible. I am sure it is something I am doing wrong. Am I correct in thinking that the code you gave me would serve well in an HTML situation?

This file is called by a simple feedback form to send me a note from my website, if that makes any difference.

Thanks!

Chris


Last edited by cmcraft on Thu May 11, 2006 4:59 am; edited 1 time in total 
hitwalker







PostPosted: Thu May 11, 2006 4:56 am Reply with quote

try it like this..

Code:


<?php
if (!isset($_POST['submit'])) {
   echo "<h1>Error</h1>\n
      <p>Accessing this page directly is not allowed.</p>";
   exit;
}

function cleanUp($data) {
   $data = trim(strip_tags(htmlspecialchars($data)));
   return $data;
}

$name      = cleanUp($_POST['name']);
$email     = cleanUp($_POST['email']);
$url       = cleanUp($_POST['url']);
$comments  = cleanUp($_POST['comments']);

if ((empty($name)) || (empty($email)) || (empty($comments))) {
   echo "<h2>Input Error</h2>\n
     <p><strong>Name</strong>, <strong>e-mail</strong> and <strong>comments</strong> are required fields. Please fill them in and try again:</p>";

   echo "<form action=\"process.php\" method=\"post\"><p>";
   echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />";
   echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />";
   echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />";
   echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />";
   echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />";
   echo "</p></form>";

   exit;
}

if (!ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$",$email)) {
echo "<h2>Input Error</h2>\n
<p>The e-mail address \"$email\" isn't valid. Please edit it and try again:</p>";

   echo "<form action=\"process.php\" method=\"post\"><p>";
   echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />";
   echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />";
   echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />";
   echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />";
   echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />";
   echo "</p></form>";

   exit;
}

$email = preg_replace("([\r\n])", "", $email);

$find = "/(content-type|bcc:|cc:)/i";
if (preg_match($find, $name) || preg_match($find, $email) || preg_match($find, $url) || preg_match($find, $comments)) {
   echo "<h1>Error</h1>\n
      <p>No meta/header injections, please.</p>";
   exit;
}

$recipient = "crafty184@gmail.com";
$subject   = "ChristopherCraft.com Feeedback";

$message   = "Name: $name \n";
$message  .= "E-mail: $email \n";
$message  .= "URL: $url \n";
$message  .= "Comments: $comments";

$headers   = "From: ChristopherCraft dot com \r\n";
$headers  .= "Reply-To: $email";

if (mail($recipient,$subject,$message,$headers)) {
   echo "<p>Mail sent successfully.</p>";
} else {
   echo "<p>Mail not sent this time.</p>";
}
echo "<scr  ipt>";
echo "<!--";
echo "var version = parseInt(navigator.appVersion)";
echo "if (version>=4 || window.location.replace)";
echo "setTimeout(\"window.location.replace('http://www.christophercraft.com')\",5000);";
echo "else";
echo "window.location.href = \"http://www.christophercraft.com\"";
echo "// -->";
echo "</scr  ipt>";
?>
 
cmcraft







PostPosted: Thu May 11, 2006 5:02 am Reply with quote

Wow. Thanks for the quick response! Should I assume that the refresh of 5000 is in seconds?
 
hitwalker







PostPosted: Thu May 11, 2006 5:03 am Reply with quote

well i think mili...lol
now its 5 seconds..
 
cmcraft







PostPosted: Thu May 11, 2006 5:36 am Reply with quote

I ask because it doesn't redirect. It just sits on the page with the confirmation of mail sent successfully. Hmmm...
 
hitwalker







PostPosted: Thu May 11, 2006 5:40 am Reply with quote

try it like this...





Code:



<?php
if (!isset($_POST['submit'])) {
   echo "<h1>Error</h1>\n
      <p>Accessing this page directly is not allowed.</p>";
   exit;
}

function cleanUp($data) {
   $data = trim(strip_tags(htmlspecialchars($data)));
   return $data;
}

$name      = cleanUp($_POST['name']);
$email     = cleanUp($_POST['email']);
$url       = cleanUp($_POST['url']);
$comments  = cleanUp($_POST['comments']);

if ((empty($name)) || (empty($email)) || (empty($comments))) {
   echo "<h2>Input Error</h2>\n
     <p><strong>Name</strong>, <strong>e-mail</strong> and <strong>comments</strong> are required fields. Please fill them in and try again:</p>";

   echo "<form action=\"process.php\" method=\"post\"><p>";
   echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />";
   echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />";
   echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />";
   echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />";
   echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />";
   echo "</p></form>";

   exit;
}

if (!ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$",$email)) {
echo "<h2>Input Error</h2>\n
<p>The e-mail address \"$email\" isn't valid. Please edit it and try again:</p>";

   echo "<form action=\"process.php\" method=\"post\"><p>";
   echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />";
   echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />";
   echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />";
   echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />";
   echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />";
   echo "</p></form>";

   exit;
}

$email = preg_replace("([\r\n])", "", $email);

$find = "/(content-type|bcc:|cc:)/i";
if (preg_match($find, $name) || preg_match($find, $email) || preg_match($find, $url) || preg_match($find, $comments)) {
   echo "<h1>Error</h1>\n
      <p>No meta/header injections, please.</p>";
   exit;
}

$recipient = "";
$subject   = "ChristopherCraft.com Feeedback";

$message   = "Name: $name \n";
$message  .= "E-mail: $email \n";
$message  .= "URL: $url \n";
$message  .= "Comments: $comments";

$headers   = "From: ChristopherCraft dot com \r\n";
$headers  .= "Reply-To: $email";

if (mail($recipient,$subject,$message,$headers)) {
   echo "<p>Mail sent successfully.</p>";
} else {
   echo "<p>Mail not sent this time.</p>";
}
?>
<sc ript>
<!--
var version = parseInt(navigator.appVersion)
if (version>=4 || window.location.replace)
setTimeout("window.location.replace('http://www.christophercraft.com')",5000);
else
window.location.href = "http://www.christophercraft.com"
// -->
</scr ipt>



If this doesnt work you could try to change it to go on submit do this ()...
 
cmcraft







PostPosted: Thu May 11, 2006 9:17 am Reply with quote

I hate to keep bugging you...but it returned this and I didn't know how to change it to on submit...

Quote:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [ Only registered users can see links on this board! Get registered or login! ] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.



--------------------------------------------------------------------------------

Apache/1.3.33 Server at [ Only registered users can see links on this board! Get registered or login! ] Port 80
 
hitwalker







PostPosted: Thu May 11, 2006 9:21 am Reply with quote

how you do that...lol
thats impossible..
You just uploaded it and used it as described?
 
cmcraft







PostPosted: Thu May 11, 2006 9:25 am Reply with quote

Absolutely. I opened process.php and copied what you gave me right in. I will try again using a new file. I will let you know.
 
cmcraft







PostPosted: Thu May 11, 2006 9:27 am Reply with quote

Same deal. I am using godaddy if that makes any difference.
 
gregexp
The Mouse Is Extension Of Arm



Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol

PostPosted: Sat May 20, 2006 3:08 am Reply with quote

now i personally have run into problems adding scripts to php so i always try to use an include funtion.

so with my thinking this is what it should look like

Code:
<?php 

if (!isset($_POST['submit'])) {
   echo "<h1>Error</h1>\n
      <p>Accessing this page directly is not allowed.</p>";
   exit;
}

function cleanUp($data) {
   $data = trim(strip_tags(htmlspecialchars($data)));
   return $data;
}

$name      = cleanUp($_POST['name']);
$email     = cleanUp($_POST['email']);
$url       = cleanUp($_POST['url']);
$comments  = cleanUp($_POST['comments']);

if ((empty($name)) || (empty($email)) || (empty($comments))) {
   echo "<h2>Input Error</h2>\n
     <p><strong>Name</strong>, <strong>e-mail</strong> and <strong>comments</strong> are required fields. Please fill them in and try again:</p>";

   echo "<form action=\"process.php\" method=\"post\"><p>";
   echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />";
   echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />";
   echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />";
   echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />";
   echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />";
   echo "</p></form>";

   exit;
}

if (!ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$",$email)) {
echo "<h2>Input Error</h2>\n
<p>The e-mail address \"$email\" isn't valid. Please edit it and try again:</p>";

   echo "<form action=\"process.php\" method=\"post\"><p>";
   echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />";
   echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />";
   echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />";
   echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />";
   echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />";
   echo "</p></form>";

   exit;
}

$email = preg_replace("([\r\n])", "", $email);

$find = "/(content-type|bcc:|cc:)/i";
if (preg_match($find, $name) || preg_match($find, $email) || preg_match($find, $url) || preg_match($find, $comments)) {
   echo "<h1>Error</h1>\n
      <p>No meta/header injections, please.</p>";
   exit;
}

$recipient = "";
$subject   = "ChristopherCraft.com Feeedback";

$message   = "Name: $name \n";
$message  .= "E-mail: $email \n";
$message  .= "URL: $url \n";
$message  .= "Comments: $comments";

$headers   = "From: ChristopherCraft dot com \r\n";
$headers  .= "Reply-To: $email";

if (mail($recipient,$subject,$message,$headers)) {
   echo "<p>Mail sent successfully.</p>";
} else {
   echo "<p>Mail not sent this time.</p>";
}
<scr ipt language=\"javascript\" type=\"text/javascript\" src=\"includes/delayscript.js\"></scr ipt>
?>


and throw this in a text file
Code:


<!--
var version = parseInt(navigator.appVersion)
if (version>=4 || window.location.replace)
setTimeout("window.location.replace('http://www.christophercraft.com')",5000);
else
window.location.href = "http://www.christophercraft.com"
// -->

now because the include is wrapped in the words script..it doesnt need the script tags

but all i did was add this code right above the ?>
Code:


<scr ipt language=\"javascript\" type=\"text/javascript\" src=\"includes/delayscript.js\"></scr ipt>


remember that in order to post all this..we had to space the <scr ipt> tags

Also the code block broke some of the code and made it a 2 liner...u MUST make sure its not brokin when u copy and paste it...use the original and just through that code in it would be ur best bet.
 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
djmaze
Subject Matter Expert



Joined: May 15, 2004
Posts: 727
Location: http://tinyurl.com/5z8dmv

PostPosted: Sat May 20, 2006 9:41 pm Reply with quote

Ehm this is the PHP forum and NOT javascript forum.
So why do i see crappy JavaScript codes to try an delay while there exists an refresh header?

Code:
<?php

header('Refresh: 5; url=http://www.christophercraft.com/');

_________________
$ mount /dev/spoon /eat/fun auto,overclock 0 1
ERROR: there is no spoon [ Only registered users can see links on this board! Get registered or login! ] 
View user's profile Send private message Visit poster's website
gregexp







PostPosted: Tue May 23, 2006 4:40 pm Reply with quote

nice to know...thanx Laughing
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©