Jump to content

Anonymous feedback form


forgottenglory

Recommended Posts

I have searched for this on the Net but couldn't come across any tutorials which explains how to do this.  I would like to build an anonymous feedback form which would contain only one text field and one submit button.  The script must be able to prevent people from submitting a blank form. 

 

Could anybody please point me in the direction of a tut that would explain how to do the above?

 

Thanks

Link to comment
Share on other sites

Try this

 

<?
// Change to your own email address
$your_email = "you@yourdomain.com";

// This is what is displayed in the email subject line
// Change it if you want
$subject = "Message via your contact form";

// This is displayed when the email has been sent
$thankyou_message = "<p>Thankyou. Your feedback has been sent.</p>";

$self = $_SERVER['REQUEST_URI'];

$message = $_POST['txtMessage'];
$send = $_POST['send'];

$msg="<p>Please fill in this form if you have any queries or suggestions.</p>";

echo ($msg);

$form = "
    <form method=\"post\" action=\"$self\">

     <p><label for=\"txtMessage\">Comments:</label>
    <textarea title=\"Please enter your message\" id=\"txtMessage\" name=\"txtMessage\" rows=\"20\" cols=\"45\">$message</textarea></p>

    <p><label> </label>
    <input type=\"submit\" class=\"sendbutton\" name=\"send\" value=\"Submit\" /></p>

</form>";

if($send)
{
    $valid=true;

if( !$message )
{ 
    $errmsg.="Please enter your message:<br />";
    $valid=false; 
}
}

if( $valid !=true )
    {
echo( "<span style=\"font-weight: bold; color:red;\">".$errmsg."</span>" . $form );
    }

else {

    // Stop the form being used from an external URL
    // Get the referring URL
    $referer = $_SERVER['HTTP_REFERER'];
    // Get the URL of this page
    $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
    // If the referring URL and the URL of this page don't match then
    // display a message and don't send the email.
    if ($referer != $this_url) {
        echo "You do not have permission to use this script from another URL.<br />";
echo "If you are behind a firewall please check your referrer settings.";
        exit;
    }

    // The URLs matched so send the email
    if( mail($your_email, $subject, $message, "From: $name <$email>"));
    {
    	// Display the thankyou message
    	echo $thankyou_message;
    }
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.