PDA

View Full Version : Building a Feedback Form in PHP



VodaHost
12-29-2005, 11:19 PM
In this tutorial we will learn how to email content collected through a form
to a specified email address.

I’ll assume that you know some basics HTML forms syntax. If not, don’t
worry, you’ll quickly pick it up as we move along. Before we get started,
make sure that your webhost supports PHP. (For those of you who are
just picking our brains)

Our feedback form

We will first create the HTML page that will contain our form. Copy and
paste the code below in your favorite text editor (e.g. Notepad), and name
the file as feedback.html

<html>
<head>
<title>Feedback Form</title>
</head>
<body>
<h1> Fill in the form below to send us your comments <h1>
<form method="post" action="feedback.php">
Name: <input name=”name” type=”text” /><br />
Email: <input name="email" type="text" /><br />
Comments:<br />
<textarea name="comments" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
</body>
</html>

If you open this file (feedback.html) in your browser, you’ll see 3 fields; a
name, an email and a comment text field. Your visitors can fill in the form
and once they click the ‘submit’ button, that data is sent to feedback.php
for processing.

You can also create your form in any WYSIWYG editor (like FrontPage,
Dreamweaver), provided that you correctly name your form elements, and
use the POST method along with the PHP file that will handle the content
collected through the form. You can also add more fields accordingly.

The feedback form PHP script

Our next step will be to create the PHP file ‘feedback.php’, which will
handle the data collected through the form, and email it back to you.
So here, we go. Once again, fire up your text editor, and copy and paste
the code below, and save the file as ‘feedback.php’:

<?php
$msg = "Name:t$namen";
$msg .= "Email:t$emailn";
$msg .= "Comments:t$commentsn";
$recipient = "youremail@domain.com (youremail@domain.com)";
$subject = "New Feedback from my site";
$mailheaders = "From:$emailn";
$mailheaders .= "Reply-To:$emailnn";
mail($recipient, $subject, $msg, $mailheaders);
header("Location: http://www.yoursite.com/thankyou.html (http://www.yoursite.com/thankyou.html)");
?>

When the content is send to feedback.php, the content in the text field
“name” will be put into the variable $name. Likewise the content of email
and comments will be put into the variable $email and $comments
respectively.

So if you’ve created additional fields, you can just place the dollar sign $ in
front of the name, to declare a variable containing the content collected in
that particular field.

You’ll also noticed that we’ve declared another variable $msg that will make
a copy of the different variables and this will be the body of our email. The
t before the variable will return a tab, while the n after the variable name
will make our move the content that follows to the next line. They basically
just provides some formatting to our message.

The $recipient variable will contain the email address where you want the
data collected to be emailed, while the $subject variable will contain the
email subject. $mailheaders is another variable that will contain the from
email address and reply-to email address. We want a "From:" header so
that we know who is sending the email to us and can reply to him/her if we
need to. The From & Reply-to are set to the senders address. Now here
comes the magic! mail() is a special PHP function that allows you to send
an email with only one line of coding. In general the mail function is as
follows:

mail(“youremail@domain.com (%E2%80%9Cyouremail@domain.com)”, “email subject”, “the message”,
“From: email@domain.com (email@domain.com)”);

Finally, we will redirect our visitor to a ‘Thanks you’ html page, using the
header() function in PHP. All you need to do is to create a thanks you
page, and save it as HTML, and add the link to the header() function.
That brings us to the end of this tutorial. You can use JavaScript to
validate your visitor’s input and you can also extend this tutorial to create
survey forms, or even ‘recommend a friend’ form

bkerske
01-04-2006, 05:18 PM
I currently have implemented a form like this but would like to add the users name and email into an mySQL database once they hit submit. Are there any tutorials on how to do this? I've searched the forum and haven't found any yet.

VodaHost
01-04-2006, 11:13 PM
No, not yet...But it's a good idea.

bkerske
01-05-2006, 03:08 PM
Below are a few links that might help your tutorial. This is actually a pretty good forum for newbies. They have a complete "newbies" section that will most likely suffice most beginners wanting to do some basic data entry into a database. I will most likely be able to solve my problem using this forum but I write embedded C code for a living and have done a little PERL (enough to be dangerous). If you are not "in" software development for a living I could see where this would be a daunting task so a tutorial would probably still be nice.

The board:
http://phpbuilder.com/board

The specific thread with PHP example of data entry into a mySQL database:

http://phpbuilder.com/board/showthread.php?t=10273562

Hope this helps someone.

DXer
02-19-2006, 11:26 PM
Please forgive me for being ignorant, but I dont know or understand how the above reply relkates to the form that you supply inside the web building software. if that form is useless why is it there.
I thought that Bluevoda was suppose to be user friendly, The reply to a novice like myself for the lack of a better word is greek. I tried to open the feedback.html in my browser but get an error message sending me on a google search.
Sorry but I have no unsderstanding of what I am told to do.
is this somthing that I have to change within the form?

When the content is send to feedback.php, the content in the text field
“name” will be put into the variable $name. Likewise the content of email
and comments will be put into the variable $email and $comments
respectively.

So if you’ve created additional fields, you can just place the dollar sign $ in
front of the name, to declare a variable containing the content collected in
that particular field.

You’ll also noticed that we’ve declared another variable $msg that will make
a copy of the different variables and this will be the body of our email. The
t before the variable will return a tab, while the n after the variable name
will make our move the content that follows to the next line. They basically
just provides some formatting to our message.

The $recipient variable will contain the email address where you want the
data collected to be emailed, while the $subject variable will contain the
email subject. $mailheaders is another variable that will contain the from
email address and reply-to email address. We want a "From:" header so
that we know who is sending the email to us and can reply to him/her if we
need to. The From & Reply-to are set to the senders address. Now here
comes the magic! mail() is a special PHP function that allows you to send
an email with only one line of coding. In general the mail function is as
follows:

Lost

VodaHost
02-20-2006, 07:54 AM
Your ignorance is forgiven, the above form is not a BlueVoda form and
it never claims to be and BlueVoda is very friendly.

Only about 40-50% of our customers use BV.The rest use FrontPage,
dreanweaver, etc....I can not not ignore the non BV customers have

This why I made the above post in the PHP section not the BV form
section. If you want to build a BV form please click the below....

http://www.vodahost.com/vodatalk/forms.html

adventurer
02-28-2006, 04:21 AM
Does the form in BlueVoda tie into a database in anyway? Is their an easy way to do that?
Thats all.

es

navaldesign
02-28-2006, 09:15 AM
No, that's a simple feedback form processing script. If you need to write or read from a database you must add a part that does this part of the work. What excactly you want to do?

adventurer
02-28-2006, 06:29 PM
FIrst off I would like have a log in form. I've read other threads about that and can use responses to there questions. I would also like to have people submit irems for sale. Which means that I need a database that will keep record of their items along with other information such as contact info, pictures associated with that item and such.

adventurer

navaldesign
02-28-2006, 06:33 PM
Till you learn all that stuff you intend to, have a look at Soholaunch, that has database, querries, loggin and upload capabilities. For a ready made script look at Fantastico, Noah's Classifieds

pratik koney
09-05-2007, 11:53 AM
In this tutorial we will learn how to email content collected through a form
to a specified email address.

I’ll assume that you know some basics HTML forms syntax. If not, don’t
worry, you’ll quickly pick it up as we move along. Before we get started,
make sure that your webhost supports PHP. (For those of you who are
just picking our brains)

Our feedback form

We will first create the HTML page that will contain our form. Copy and
paste the code below in your favorite text editor (e.g. Notepad), and name
the file as feedback.html

<html>
<head>
<title>Feedback Form</title>
</head>
<body>
<h1> Fill in the form below to send us your comments <h1>
<form method="post" action="feedback.php">
Name: <input name=”name” type=”text” /><br />
Email: <input name="email" type="text" /><br />
Comments:<br />
<textarea name="comments" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
</body>
</html>

If you open this file (feedback.html) in your browser, you’ll see 3 fields; a
name, an email and a comment text field. Your visitors can fill in the form
and once they click the ‘submit’ button, that data is sent to feedback.php
for processing.

You can also create your form in any WYSIWYG editor (like FrontPage,
Dreamweaver), provided that you correctly name your form elements, and
use the POST method along with the PHP file that will handle the content
collected through the form. You can also add more fields accordingly.

The feedback form PHP script

Our next step will be to create the PHP file ‘feedback.php’, which will
handle the data collected through the form, and email it back to you.
So here, we go. Once again, fire up your text editor, and copy and paste
the code below, and save the file as ‘feedback.php’:

<?php
$msg = "Name:t$namen";
$msg .= "Email:t$emailn";
$msg .= "Comments:t$commentsn";
$recipient = "youremail@domain.com (youremail@domain.com)";
$subject = "New Feedback from my site";
$mailheaders = "From:$emailn";
$mailheaders .= "Reply-To:$emailnn";
mail($recipient, $subject, $msg, $mailheaders);
header("Location: http://www.yoursite.com/thankyou.html (http://www.yoursite.com/thankyou.html)");
?>

When the content is send to feedback.php, the content in the text field
“name” will be put into the variable $name. Likewise the content of email
and comments will be put into the variable $email and $comments
respectively.

So if you’ve created additional fields, you can just place the dollar sign $ in
front of the name, to declare a variable containing the content collected in
that particular field.

You’ll also noticed that we’ve declared another variable $msg that will make
a copy of the different variables and this will be the body of our email. The
t before the variable will return a tab, while the n after the variable name
will make our move the content that follows to the next line. They basically
just provides some formatting to our message.

The $recipient variable will contain the email address where you want the
data collected to be emailed, while the $subject variable will contain the
email subject. $mailheaders is another variable that will contain the from
email address and reply-to email address. We want a "From:" header so
that we know who is sending the email to us and can reply to him/her if we
need to. The From & Reply-to are set to the senders address. Now here
comes the magic! mail() is a special PHP function that allows you to send
an email with only one line of coding. In general the mail function is as
follows:

mail(“youremail@domain.com (%E2%80%9Cyouremail@domain.com)”, “email subject”, “the message”,
“From: email@domain.com (email@domain.com)”);

Finally, we will redirect our visitor to a ‘Thanks you’ html page, using the
header() function in PHP. All you need to do is to create a thanks you
page, and save it as HTML, and add the link to the header() function.
That brings us to the end of this tutorial. You can use JavaScript to
validate your visitor’s input and you can also extend this tutorial to create
survey forms, or even ‘recommend a friend’ form


dear friend

i did the code you gave and everything was fine i can go to thank you page and no errors but i cannot receive any emails from the feedback form. in email@domain.com i have put my email address but no email. why is that.please helpme

navaldesign
09-05-2007, 04:33 PM
Ok, these are the VERY old tutorials (i don't even understand where you have found them) that explained how to hand code a form and the thank you page.

there is no need to do so, because now BlueVoda has a built in form builder, and the php part for the thank you page is also much easier. Please watch BlueVoda Form Tutorial 1 (http://www.vodahost.com/vodatalk/forms/9349-bluevoda-forms-tutorial-part-1-a.html) , and MOST IMPORTANT, read the text UNDER the multimedia tutorial.

alienz
05-23-2008, 08:39 AM
hi admin
i have used the feedback form script as given here. but what i get in my email is these three words - name:temail:tcomment:t

whats wrong?????? my site is loaded and others are waiting for the feedback form

alienz
05-23-2008, 08:46 AM
someone please help me out ............

navaldesign
05-23-2008, 09:07 AM
Please provide a link to your form page, we just can see through walls...

And, as i said, do NOT follow the instruction above.

If you are a VodaHost client and a BlueVoda user, please watch these tutorials:

BlueVoda Forms Tutorial Part 1 (http://www.vodahost.com/vodatalk/forms/9349-bluevoda-forms-tutorial-part-1-a.html)

Form Wizard Tutorial (http://www.vodahost.com/vodatalk/forms/35915-form-wizard-tutorial.html)

thompsonay
10-05-2008, 03:03 PM
I implemented this form and it works! When i say that it works, the issues that i have had as a beginner with this form has been solved; however, i did not receive back the information to my email. any suggestions?

davidundalicia
10-05-2008, 03:07 PM
Please post a link to your form and if you use BV why not use the form wizard...........

Cpt Random
03-12-2009, 09:49 PM
worked on my ******* server but not on my clients private server. any thoughts? do you have to have certain software installed to use php on a server?

Cpt Random
03-12-2009, 09:57 PM
go ***** server... thats weird..