PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
“I think basiclly you want that lost_name along with a bunch of variables (just guessing, since you haven't showed the mail sending part) accessible on the second thank-you page.”
You see what I was really trying to do is have this all on one page and not use a second page at all. For example
If the fields are blank
Show ‘form’
if fields are filled and validate ok
don’t show form show thank you
If you copy and paste the complete code below you will see what is happening. If all the fields are correctly filled in the page submits but all the remaining code gets terminated ie the “Hi I should still see this after the form is submitted!” bit of text should still be there after I submit. This is the bit that is driving me nutters!
Thanks for your patience with me on this.
Brian
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Set A Title Here</title>
</head>
<body>
<?PHP
// Test whether the POST array has been set and makes certain
// variables are initialized with no content.
$pattern = '/^\wї-.\w]*@(ї-a-z0-9]+\.)+їa-z]{2,4}$/i';
if ($_POST && array_key_exists('sendCom',$_POST)) {
$nomessage='';
$error=array();
$error_email=array();
$message='';
$lost_email= $_POSTї'lost_email'];
// Check each field and build errors array if problems found
if (isset($_POSTї'lost_email']) && !empty($_POSTї'lost_email'])) {
$message=strip_tags($_POSTї'lost_email']);
}
else {
$nomessage = 'Email Required';
}
if (isset($_POSTї'lost_name']) && !empty($_POSTї'lost_name'])) {
$lost_name=trim($_POSTї'lost_name']);
}
else {
$errorї'lost_name'] = 'Name Required';
}
if (empty($_POSTї'lost_email']))
{// validation of email if inserted otherwise ignore
} else {
if (!preg_match($pattern,$lost_email)) $error_emailї'invalid'] = 'ERROR! Your email address seems to be invalid. <br> It should be similar to the following: info@me.com';
}
// If no errors, send email and redirect to acknowledgment page
if (!$nomessage && !$error) {
if (!$nomessage && !$error_email){
//mail($to,$subject,$message,$additional_headers);
if (isset($error_email) && empty($error_email)) {
if (!empty($_POSTї'lost_email']) && !empty($_POSTї'lost_name'])) {
echo "Thank you " .$_POSTї'lost_name'] .", your message was successfully sent<br>";
}}}}}
//Otherwise, display the form to user
else {
?>
<table border="0" cellpadding="0" cellspacing="0" class="tbl_outer" id="tbl_outer"><tr><td class="mainContent">
</td>
</tr>
<tr>
<td id="error"><?php
if (isset($error_email)) {
foreach ($error_email as $key => $value) {
echo $value.'<br />';
}
}
?></td>
</tr>
<tr>
<td><form method="post" name="form1" action="<?php $_SERVERї'PHP_SELF']?>">
<table>
<tr valign="baseline">
<td align="right" nowrap class="error" id="error">* Name: <br>
<?php
if (isset($error)) { // Display error messages. Otherwise skip table row.
// Loop through error messages and display
foreach ($error as $key => $value) {
echo $value.'<br />';
}
}
?></td>
<td><input type="text" name="lost_name" id="" size="32" value="<?php if (isset($_POSTї'lost_name'])) echo $_POSTї'lost_name'];?>" ></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="error" id="error"> Membership number (if known):<br></td>
<td><input type="text" name="lost_membership_no" id="lost_membership_no" size="32" value="<?php if (isset($_POSTї'lost_membership_no'])) echo $_POSTї'lost_membership_no'];?>" ></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">*Email Address:
<?php if (isset($nomessage) && !empty($nomessage)) {
echo $nomessage; } else {
} ?>
</td>
<td><input type="text" name="lost_email" id="lost_email" value="<?php if (isset($_POSTї'lost_email'])) echo $_POSTї'lost_email'];?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">* Required Field </td>
<td><input name="sendCom" type="submit" id="sendCom" value="Post Message" />
<input name="Reset" type="reset" value="Reset"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p></td>
</tr>
</table>
<? } ?>
Hi, I should now see this after the form is submitted!
</body>
</html>
Thanks so much for this. But and there’s always a but! I had originally started out (many hours ago) using the ‘else’ clause as it seemed the obvious method to use but it stopped the validation script running and unfortunately this is the same with your version.
I’m still playing around with this but maybe you might see a way around this bit.
I owe you on this one.
Many thanks
Brian
Hi,
Sorry to confuse you on this. Basically I copied and pasted the revised version you posted and if I hit the submit button the form submits without checking for a valid email or blank fields.
Apologies if I have missed something obvious.
Ta
Brian
See you have put there the validation bit and it is running too but the prob is you haven't set any statements for outputting error messages. I thought you simply want to display confirmation if the mail was sent. If you want to put the error outputting thing you can use javascript for that or edit the current script and add error output.
Thanks
When you say “you haven't set any statements for outputting error messages.” I’m not too sure I follow. If I was to simply remove the else clause that you popped in then the error message (that is already on the page) will run so do you mean that I should change them from their current location to somewhere else?
Ta again
Brian
was successfully sent<br>";
}}}}}
^ Put Else Clause Before This Last Brace Here
//Otherwise, display the form to user
else {
and tell the user whatever went wrong with the submission.