Setting Up A Feedback Form in PHP Part 1
Back in the early days of web design you couldn’t do much in order to tell send email to a website owner, you had to use there email. However, thanks to languages like CGI and perl, you could build forms on your website and with a little script the message would be sent from the website to your email account. Once PHP came along, it made it a whole lot easier and you could get creative with the PHP/HTML form.
<div> <p>Please complete this form to submit your feedback:</p> <form action="handle_form.php"> <p>Name: <select name="title"> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Ms.">Ms.</option> </select> <input type="text" name="name" size="20" /> </p> <p>Email Address: <input type="text" name="email" size="20" /> </p> <p>Response: This is... <input type="radio" name="response" value="excellent" /> excellent <input type="radio" name="response" value="okay" /> okay <input type="radio" name="response" value="boring" /> boring</p> <p>Comments: <textarea name="comments" rows="3" cols="30"></textarea> </p> <input type="submit" name="submit" value="Send My Feedback" /> </form> </div>
Sure the form doesn’t look much, but with CSS it will look a lot better, but that isn’t important right now as our goal is to send a feedback email to my email account. So to do that we have to amke two files, first being the HTML file or PHP file or whatever extension you use to put your form in. The second file itself will be an external php script that will copy the data that was inputted into the form and send it to its destination.
As for what the PHP code itself is going to look like take a look below and then look back and forth between this code and the HTML and you will eventually see how everything is connected.
// This page receives the data from feedback.html. // It will receive: title, name, email, response, comments, and submit in $_POST. $title = $_POST['title']; $name = $_POST['name']; $response = $_POST['respohttp://saint-michael.trap17.com/blog/wp-admin/post-new.phpnse']; $comments = $_POST['comments']; // Print the received data: print "<p>Thank you, $title $name, for your comments.</p> <p>You stated that you found this example to be '$response' and added:<br />$comments</p>";
As you notice from the code instead of emailing it to my email account all it will do is display whatever information you put into the form and so copy and paste the code into there respect HTML file and PHP file, upload it up and see what PHP with a feedback form.
label {
width: 4em;
float: left;
text-align: right;
margin-right: 0.5em;
display: block
}
.submit input {
margin-left: 4.5em;
}
input {
color: #781351;
background: #fee3ad;
border: 1px solid #781351
}
.submit input {
color: #000;
background: #ffa20f;
border: 2px outset #d7b9c9
}
fieldset {
border: 1px solid #781351;
width: 20em
}
legend {
color: #fff;
background: #ffa20c;
border: 1px solid #781351;
padding: 2px 6px
}
Ok so we added a bit of style just to show you what you can do with a form, it was rather quick putting the CSS together, but if you take the time and match it with the rest of your website it will surely be a sexy form.
<div style="width:20em;">
<fieldset>
<legend>Please complete this form to submit your feedback:</legend>
<form action="handle_form.php" method="post">
<p>Name:
<select name="title">
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
</select>
<input type="text" name="name" size="20" />
</p>
<p>Email Address:
<input type="text" name="email" size="20" />
</p>
<p>Response: This is...
<input type="radio" name="response" value="excellent" />
excellent
<input type="radio" name="response" value="okay" />
okay
<input type="radio" name="response" value="boring" />
boring</p>
<p>Comments:
<textarea name="comments" rows="3" cols="30"></textarea>
</p>
<input type="submit" name="submit" value="Send My Feedback" />
</form>
</fieldset>
</div>













Leave your response!
You must be logged in to post a comment.