Love disolves anxiety and depression

I have been writing and developing my very first ever PHP script- a feedback form for my website.

This uses a basic HTML form to gather some feedback information from your visitors. It then posts this information to a PHP file, which returns a confirmation page. It also gets your web server to email you the feedback.

Although it is so simple, it took me a long time. But in the end I have a professional looking script, which you are welcome to use for free and modify to your particular needs and website.

I used an open source captcha image script I found on Google with my feedback form to stop the possibility of robots visiting my site that fill out forms and send spam.

So here is the script for form.php:
<?php
session_start();
if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
$output = ‘<html>
<head>
<title>Feedback Form- Confirmed</title>
<link rel=”stylesheet” href=”../css/feedback.css” type=”text/css”>
</head>
<h1>Dear ‘.$_POST["FirstName"].’, thank you for your feedback!</h1>

You entered the following details:
<ul>
<li>Your name is ‘.$_POST["FirstName"].’ ‘.$_POST["LastName"].’</li>
<li>You are ‘.$_POST["Age"].’ years old and ‘.$_POST["sex"].’</li>
<li>You are from ‘.$_POST["Country"].’</li>
<⁄ul>
<p>You rate this site: </p> <p class=”gold”>’.$_POST["Value"].’</p>
<p>Your reason for this: </p> <p class=”green”>’.$_POST["comments"].’</p></p>
<p>And this is your suggestion on how to improve the site: </p> <p class=”green”>’.$_POST["improvements"].’</p>
<br><br>
<p>Click <a href=”../index.html”>Here</a> to return back to the main page</p>.
</body>
</html>’;

$to = “example@example.com”;
$subject = “Online Feedback Form - Example.Com”;
$message = $output;
$from = $_REQUEST["EmailAddress"];
$headers = “From: $from”\r\n”;
$headers = “Content-type: text/html\r\n”;

mail($to,$subject,$message,$headers);

echo $output;

unset($_SESSION['security_code']);

} else {

// Insert your code for showing an error message here

echo “The security code you typed seems to be invalid. Please go back, reload the page and try again. The information you typed in should still be there. Thanks.”;
}

?>


This is an example of a form you can use in HTML along with the form.php file and how it matches up:

<code>
<html>
<body>
<fieldset>
<legend>

AnxietyMadeWell.Com Feedback Form:
</legend>
<form name=”input” action=”feedback.php” method=”post”>
First name:
<input type=”text” name=”FirstName” size=”20″>
Last name:
<input type=”text” name=”LastName” size=”20″>
<br><br>
Your age:
<input type=”text” name=”Age” size=”4″>
<br><br>
Your Country/Location:
<input type=”text” name=”Country” size=”20″>
<br><br>
Email address:
<input type=”text” name=”EmailAddress” size=”20″><br><br>

<input type=”radio” name=”sex” value=”Male”> Male
<br>
<input type=”radio” name=”sex” value=”Female”> Female

<br><br>

How do you rate this site?<br><br>

Excellent:
<input type=”radio” name=”Value” value=”Excellent”>

Good:
<input type=”radio” name=”value” value=”Good”>

Okay:
<input type=”radio” name=”value” value=”Okay”>

Bad:
<input type=”radio” name=”value” value=”Bad”>

Terrible:
<input type=”radio” name=”value” value=”Terrible”><br><br>

<textarea rows=”5″ cols=”30″ name=”comments”>Why?</textarea>

<br><br>

<textarea rows=”5″ cols=”30″ name=”improvements”>How could this site be improved?</textarea>

<br><br>

<img src=”CaptchaSecurityImages.php”>
Security Code:
<input id=”security_code” name=”security_code” type=”text” size=”5″>
<br><br>

<input type=”submit” value=”Submit”>

</form>
</fieldset>
</body>
</html>

Leave a Reply

You must be logged in to post a comment.