13-12-2004, 06:29
|
#1 (permalink)
|
|
Senior Member
Join Date: Oct 2004
Location: Chester
Posts: 364
|
mailform()
Can anyone see what I have done wrong with this form, it works so much as it sends the information, I test the script and I receive the email with the name, email address and comments, it also sends an email to the return email address. But it doesn't seem to verify the script if I leave the form blank or if I enter an invalid email address, and also the header doesn't work, the page is not redirected to the thanks.php page.
PHP Code:
<?php require_once('Connections/connNickToye.php'); ?>
<?php
$maxRows_rsRecentArticles = 5;
$pageNum_rsRecentArticles = 0;
if (isset($_GET['pageNum_rsRecentArticles'])) {
$pageNum_rsRecentArticles = $_GET['pageNum_rsRecentArticles'];
}
$startRow_rsRecentArticles = $pageNum_rsRecentArticles * $maxRows_rsRecentArticles;
mysql_select_db($database_connNickToye, $connNickToye);
$query_rsRecentArticles = "SELECT * FROM articles ORDER BY pub_date DESC";
$query_limit_rsRecentArticles = sprintf("%s LIMIT %d, %d", $query_rsRecentArticles, $startRow_rsRecentArticles, $maxRows_rsRecentArticles);
$rsRecentArticles = mysql_query($query_limit_rsRecentArticles, $connNickToye) or die(mysql_error());
$row_rsRecentArticles = mysql_fetch_assoc($rsRecentArticles);
if (isset($_GET['totalRows_rsRecentArticles'])) {
$totalRows_rsRecentArticles = $_GET['totalRows_rsRecentArticles'];
} else {
$all_rsRecentArticles = mysql_query($query_rsRecentArticles);
$totalRows_rsRecentArticles = mysql_num_rows($all_rsRecentArticles);
}
$totalPages_rsRecentArticles = ceil($totalRows_rsRecentArticles/$maxRows_rsRecentArticles)-1;
mysql_select_db($database_connNickToye, $connNickToye);
$query_rsLinks = "SELECT * FROM inspiration ORDER BY title ASC";
$rsLinks = mysql_query($query_rsLinks, $connNickToye) or die(mysql_error());
$row_rsLinks = mysql_fetch_assoc($rsLinks);
$totalRows_rsLinks = mysql_num_rows($rsLinks);
?>
<?php
$editFormAction = $_SERVER['PHP_SELF'];
$pattern = '/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';
if ($_POST && array_key_exists('sendCom',$_POST)) {
$nomessage='';
$error=array();
$message='';
$email='';
$con_email='';
$adminaddress = "info@nicktoye.co.uk";
$siteaddress ="http://www.nicktoye.co.uk";
$sitename = "Nick Toye";
// Check each field and build errors array if problems found
if (isset($_POST['comments']) && !empty($_POST['comments'])) {
$message=strip_tags($_POST['comments']);
}
else {
$nomessage = 'You have not entered any comments';
}
if (isset($_POST['email']) && !empty($_POST['email'])) {
$email=trim($_POST['email']);
}
else {
$error['email'] = 'You have not given a return email address';
}
if (isset($_POST['con_email']) && !empty($_POST['con_email'])) {
$con_email=trim($_POST['con_email']);
if($email != $con_email) $error['nomatch'] = 'Your emails don\'t match';
}
else {
$error['confirm'] = 'Please confirm your email address';
}
if ($email && $con_email) {
if ($email == $con_email) {
if (!preg_match($pattern,$email)) $error['invalid'] = 'That appears to be an invalid email address';
}
}
mail ("$adminaddress","Quote Request",
"A visitor at $sitename has left the following information\n
Name: $name
Email: $email\n
The visitor commented:
------------------------------
$message
","FROM:$adminaddress" ) ;
//This sends a confirmation to your visitor
mail ("$email","Thank You for visiting $sitename",
"Hi $name,\n
Thank you for your interest in $sitename!\n
Cheers, we will get back to you as soon as possible
$sitename
$siteaddress","FROM:$adminaddress") ;
// If no errors, send email and redirect to acknowledgment page
if (!$nomessage && !$error) {
header('Location: thanks.php');
exit();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>NickToye 2005: Contract Me</title>
<link href="/css/myStyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="inner">
<div id="header"></div>
<ul id="nav">
<li id="home"><a href="index.php">HOME </a></li>
<li id="about"><a href="about.php">ABOUT</a></li>
<li id="blog"><a href="blog.php">BLOG</a></li>
<li id="work"><a href="work.php">WORK</a></li>
<li id="contract"><a href="contract.php">CONTRACT ME</a></li>
<li id="admin"><a href="admin/adminIndex.php">ADMIN</a></li>
</ul>
<div id="content">
<span class="title"></span>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<dl>
<dt>
<label for="name">Name:</label>
</dt>
<dd>
<input name="name" type="text" class="wideBox" id="name" />
</dd>
<dt>
<label for="email">Email:</label>
</dt>
<dd>
<input name="email" type="text" class="wideBox" id="email" />
</dd>
<dt>
<label for="comment">Comment:</label>
</dt>
<dd>
<textarea name="comments" class="textArea" id="comments"></textarea>
</dd>
<dt>
<input name="sendCom" type="submit" class="button" value="Submit" />
</dt>
</dl>
</form>
</div>
<div id="sidebar">
<span class="sidebarHeader">Recent Articles </span>
<ul>
<?php do { ?>
<li><a href="viewArticle.php?article_id=<?php echo $row_rsRecentArticles['article_id']; ?>"><?php echo $row_rsRecentArticles['title']; ?></a></li>
<?php } while ($row_rsRecentArticles = mysql_fetch_assoc($rsRecentArticles)); ?>
</ul>
<span class="sidebarHeader">Inspiration</span>
<p></p>
<ul>
<?php do { ?>
<li><a href="<?php echo $row_rsLinks['link']; ?>"><?php echo $row_rsLinks['title']; ?></a></li>
<?php } while ($row_rsLinks = mysql_fetch_assoc($rsLinks)); ?>
</ul>
<span class="sidebarHeader">Icons</span>
<ul>
<li><a href="/icons1.php">Internet Superhighway</a></li>
<li><a href="/icons2.php">Home</a></li>
</ul>
</div>
<div class="clearer"></div>
</div>
</div>
<div id="footer"><span class="style2">
Powered By <a href="http://www.macromedia.com/software/dreamweaver/">Dreamweaver MX 2004</a>, <a href="http://www.mysql.com/">MySQL</a> and <a href="http://www.php.net/">PHP</a>.
Copyright Nick Toye 2004<br />
<a href="http://validator.w3.org/check/referer">XHTML</a>, <a href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.nicktoye.co.uk/css/myStyle.css">CSS</a> </span></div>
</body>
</html>
<?php
mysql_free_result($rsRecentArticles);
mysql_free_result($rsLinks);
?>
Many thanks in advance.
BTW - I have decided to leave in the confirm email address variables, but I have decided not to use them in the form, just yet.
|
|
|
|