Forum Moderators: coopster
Anyone shed some light on the problem?
<?php
// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there's an error, add an error message to the error array
// using the field name as the key.
if ($_POST['name']=='')
$arrErrors['name'] = 'Please provide your name.';
if ($_POST['phone']=='')
$arrErrors['phone'] = 'Please provide your mobile number.';
if (!preg_match("/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/", $_POST['email']) ) {
$arrErrors['email'] = 'Please provide a valid email address.';}
if ($_POST['inquiry']=='')
$arrErrors['inquiry'] = 'Please type in your Shout Out.';
if (count($arrErrors) == 0) {
// If the error array is empty, there were no errors.
// Insert form processing here.
$email = $_POST['email'] ;
$name = stripslashes($_POST['name']) ;
$inquiry = stripslashes($_POST['inquiry']) ;
$phone = stripslashes($_POST['phone']) ;
$to="email@email.com.au";
$mailheaders = "MIME-Version: 1.0\n";
$mailheaders .= "Content-type: text/html; charset=iso-8859-1\n";
$mailheaders .= "From: $email" . "\r\n" ;
$mailheaders .= "Cc: ";
$message="
-snip-
";
mail( $to, "website - Shout out", $message, $mailheaders);
header( "Location: [website.com.au...] );
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p><img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><span class="list">Please check the following and try again:</span></p><ul class="list">';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div><p>';
}
}
?>
<?php echo $strError;?>
<form method="post" action="<?php echo $PHP_SELF;?>">
<fieldset >
<legend class="heading">Send us a Shout Out</legend>
<p<?php if (!empty($arrErrors['name'])) echo ' class="formerror"';?>>
<label for="name" class="content">Name:</label>
<br>
<input name="name" type="text" id="name" value="<?php echo $_POST['name']?>">
<?php if (!empty($arrErrors['name'])) echo '<img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['name'].'</span>';?>
</p>
<p<?php if (!empty($arrErrors['phone'])) echo ' class="formerror"';?>>
<label for="phone" class="content">Mobile Phone:</label>
<br>
<input name="phone" type="text" id="phone" value="<?php echo $_POST['phone']?>">
<?php if (!empty($arrErrors['phone'])) echo '<img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['phone'].'</span>';?>
</p>
<p<?php if (!empty($arrErrors['email'])) echo ' class="formerror"';?>>
<label for="email" class="content">Email:</label>
<br>
<input name="email" type="text" id="email" size="35" value="<?php echo $_POST['email']?>">
<?php if (!empty($arrErrors['email'])) echo '<img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['email'].'</span>';?>
</p>
<p<?php if (!empty($arrErrors['inquiry'])) echo ' class="formerror"';?>>
<label for="inquiry" class="content">Shout Out :</label>
<br>
<textarea name="inquiry" cols="28" rows="5" id="inquiry"><?php echo $_POST['inquiry']?></textarea>
<?php if (!empty($arrErrors['inquiry'])) echo '<img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><span class="errortext">'.$arrErrors['inquiry'].'</span>';?>
</p>
<p<?php if (!empty($arrErrors['inquiry'])) echo ' class="formerror"';?>> </p>
<input type="submit" name="Submit" value="Submit">
</fieldset>
</form>
I have the right file extentions and everything and it does send the email, it just doesnt go to the thankyou page it reloads the contact page again.
Whats happening here?
Notice: Undefined variable: strError in /var/virtual/web/w1425/html/contact.php on line 181
Notice: Undefined index: inquiry in /var/virtual/web/w1425/html/contact.php on line 219
those lines are as follows
- 181 - <?php echo $strError;?>
- 219 - <textarea name="inquiry" cols="28" rows="5" id="inquiry"><?php echo $_POST['inquiry']?></textarea>
So whats the solution
$strError = '';
If you look at your source code you might see undefined indexes for the other fields too. You need to check that the variables are set by using isset() [uk.php.net].
<textarea name="inquiry" cols="28" rows="5" id="inquiry"><?php echo (isset($_POST['inquiry'])? $_POST['inquiry'] : '')?></textarea>
dc
Warning: Cannot modify header information - headers already sent by (output started at /var/virtual/web/w1425/html/contact.php:12) in /var/virtual/web/w1425/html/contact.php on line 163
line 163 is header( "Location: http://www.example.com.au/thank.htm" );
so what do i do about this problem
[edited by: jatar_k at 3:58 pm (utc) on May 21, 2006]
[edit reason] generalized domain [/edit]