PHP: Feedback Form Help
I have a feedback form on my website. When someone fills in the form and submits it, the form leads to an another page and says that your message has been sent.
Now I want the message to be displayed on the same page where the form is located. That is when someone submits the form the same page should be loaded again bearing an extra highlighted message that the message has been sent....
In short I want action page to be the same has the form page. But i dont want to make two similar pages with form and make one of them the action page because that will be the same case as i mentioned earlier.
Please tel me how to do that....
The Coder posted this at 23:03 — 4th January 2007.
He has: 71 posts
Joined: Nov 2006
Currently I am using this script:
<?
$name=$_POST['name'];
$company=$_POST['company'];
$email=$_POST['email'];
$telephone=$_POST['telephone'];
$msg=$_POST['msg'];
$to="[email protected]";
$message="Query From Your Website\n\nName: $name \nCompany: $company \nEmail: $email \nTelephone: $telephone \nMessage: $msg";
if(mail($to,"Query From Your Website",$message,"From: $email\n")) {
echo "Thanks $name,We will turn to you soon.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>
Someone please help!!!!!!! Its urgent!!!!!
The Coder posted this at 02:08 — 5th January 2007.
He has: 71 posts
Joined: Nov 2006
A web developer has given me a solution to my above question. But it is too bried to understand. Can some with wider PHP knowledge explain it to me. His Suggested Solution Is:
After success, just redirect to the form page with a qry string.
display message based on that.
eg: page.php?msg=success
Code:
<?php
$msg = (isset($HTTP_POST_VARS['msg']))? $HTTP_POST_VARS['msg'] : ( (isset($HTTP_GET_VARS['msg'])) ? $HTTP_GET_VARS['msg'] : '' );
if($msg == 'success')
{
echo 'Hey, your message has been sent. Have a nice time. C ya!';
}
JeevesBond posted this at 03:18 — 19th January 2007.
He has: 3,956 posts
Joined: Jun 2002
The solution given is a bit esoteric, it can also be written as:
<?php
if (isset($HTTP_POST_VARS['msg'])) {
$msg = $HTTP_POST_VARS['msg'];
// If the form has been submitted via POST variables
} else if (isset($HTTP_GET_VARS['msg'])) {
$msg = $HTTP_GET_VARS['msg'];
// If the form has been submitted via GET variables (e.g. index.php?msg=success)
} else {
$msg = '';
}
if($msg == 'success')
{
echo 'Hey, your message has been sent. Have a nice time. C ya!';
}
?>
Hopefully this will make a little more sense, I always tend to write code the long way (rather than take shortcuts) as it's easier to understand for anyone (including me) reading it in the future.
a Padded Cell our articles site!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.