Forum Moderators: coopster

Message Too Old, No Replies

formmail success text instead of redirect

         

jake66

6:49 am on Jan 9, 2006 (gmt 0)

10+ Year Member



i would like to display a "thank you for the submission" at the top of the input boxes, instead of redirecting to a white page with black text.. or a complete page redirect.

like this:

[success/error message here, but hidden until there's a reason to display something]
- name box
- input box
- comment box
- submit button

here is a snippet of what i currently have. what this portion does, if there's an error.. the user is redirected to a white page and in the upper left-hand corner they are told "error! bla bla..." or "success!"

---

if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))
{
echo "That is not a valid email address."
."try again.";
exit;
}

mail($toemail, $subject, $body, $headers);
echo "Thanks!";

---end of form---

vevs

9:39 am on Jan 9, 2006 (gmt 0)

10+ Year Member



you can use this on your php page:

<body>
<?
if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))
{
echo "That is not a valid email address."
."try again.";
} elseif (ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)) {
Thank you.
};
?>

<form....>
- name box - value='<? echo $name;?>'
- input box
- comment box
- submit button
</form>
</body>

the web form will always be at the bottom. You can also add values for the input so on email error the name and comment can be automatically filled in. But you should also check if the email was sent or not.

Hope this helps.

Regards,
Vevs

jake66

12:18 am on Jan 11, 2006 (gmt 0)

10+ Year Member



that still redirected any errors to the white page with black text :(

dreamcatcher

10:01 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something like this should do:


<?php

if (isset($_POST['submit']))
{
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$comments = trim($_POST['comments']);

$errors = false;

if ($name=='' ¦¦ $email=='' ¦¦ $subject=='' ¦¦ $comments=='')
{
$errors = true;
}

}

?>
<html>
<head><title></title>
</head>

<body>
<?php
if (isset($_POST['submit']) && $errors)
{
echo "Please complete all fields!";
}
if (isset($_POST['submit']) &&!$errors)
{
echo "Thank you! Message Sent!";
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="name"><br>
E-Mail: <input type="text" name="email"><br>
Subject :<input type="text" name="subject"><br>
Comments: <textarea name="comments" rows="5" cols="20"></textarea>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

Thats just cheap and nasty, but hopefully you get the idea. I haven`t tested it, but should give you some starters. Note that if you copy and paste, re-type the pipes.

dc

jake66

11:14 pm on Jan 14, 2006 (gmt 0)

10+ Year Member



i keep getting an error:
Parse error: parse error, unexpected T_STRING in /home/**/public_html/test.php on line 12

on this line:
if ($name=='' ¦¦ $email=='' ¦¦ $subject=='' ¦¦ $comments=='')

any suggestions?

dreamcatcher

12:05 am on Jan 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To re-iterate:

Note that if you copy and paste, re-type the pipes.

dc