Forum Moderators: phranque

Message Too Old, No Replies

Feedback form script?

What's a good feedback form script?

         

pood

6:38 pm on May 2, 2007 (gmt 0)

10+ Year Member



I'd like to add an feedback form for people that answers our job listings.

What's a good/free script? Doesn't really matter language it's programmed in.

music_man

7:32 am on May 4, 2007 (gmt 0)

10+ Year Member



Hi!

I just wrote one for my foray into degradeable Ajax.

You need php for this. Just call it "feedback.php".

Here it is (no copyright, just use at your own risk):


<?php
if (isset($_POST['submit'])) {
$subject = "Feedback!";
$to = "youremail@yoursite.com";
$ajax = $_GET['ajax'];
$emailAddress = $_POST['emailAddress'];
$name = $_POST['name'];
// Message
$query = $_POST['query'];
$message .= "You have feedback!<br /><br />";
$message .= "$name($emailAddress) says:<br /><br />";
$message .= nl2br($query);
$message .= "<br /><br />Signed<br /><br />";
$message .= "<i>Your faithful feedback form :)</i>";
// From
$headers = 'From: feedback@yoursite.com' . "\r\n" .
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);
if ($ajax) {
header("Location: feedback.php?msg=thanks");
} else {
echo 'Thanks!';
exit;
}
}
?>
<script type="text/javascript">
function $(elem) {
var c;
c = document.getElementById(elem);
return c;
}
function doFeedback()
{
var obj;
// Try normal ajax
try{
obj=new XMLHttpRequest();
}
// If that doesn't work, catch the error and try another object - MSXML
catch(e) {
try {
obj=new ActiveXObject("Msxml2.XMLHTTP");
}
// Try MS XMLHTTP
catch(e) {
try {
obj=new ActiveXObject("Microsoft.XMLHTTP");
}
// If all that fails, give an error because they suck
catch(e) {
alert("Your browser can't HANDLE this app.");
return false;
}
}
}
obj.onreadystatechange = function(){
if (obj.readyState == 1) {
$('feedback').innerHTML = 'Sending...';
} else if (obj.readyState == 4) {
$('feedback').innerHTML = 'Thanks';
}
}
var uid;
var e;
var n;
var q;
var url;
var str;
e=$('emailAddress').value;
n=$('name').value;
q=$('query').value;
// Make a string
str = "submit=true&emailAddress="+e+"&name="+n+"&query="+q;
uid = Math.random();
str += "&uid="+uid;
url = "feedback.php";
// No question mark needed
obj.open("POST",url,true);
obj.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
obj.send(str);
return false;
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<title></title>
</head>
<body>
<?php if ($_GET['msg'] == '') {
?>
<form method="POST" action="feedback.php?ajax=FALSE"
onsubmit="return doFeedback();">
<div id="feedback">
<label for="emailAddress">Email address: </label> <input type="text" name="emailAddress" id="emailAddress">
<br /><br />
<label for="name">Name: </label> <input type="text" name="name" id="name">
<br /><br />
<label for="query">Query: </label><textarea name="query" id="query" rows="10" cols="30"></textarea>
<br /><br />
<input type="submit" name="submit" id="submit" value="Send &raquo;" />
</div>
</form>
<?php } else {
echo $_GET['msg'];
}
?>
</body>
</html>