Jump to content

Feedback Form - Help!


younis

Recommended Posts

The following code used to work in PHP 4, but it no longer works under PHP 5. Can someone take a look and let me know what needs fixing please? I'm not new to PHP, but I'm not an expert.

<?

// Set page variables.
$title = "Feedback Form";
$back = "";
$bg = '000066';
$text = 'ffffff';
$link = 'ffff00';
$vlink = 'ff0000';
$trans = 'spinoutin';
$btntag = 'text=000070 insetselection';
$txtbxtag = 'bgcolor=ffffff text=000070 cursor=ff autoactivate nohighlight';
$ip = $_SERVER['REMOTE_ADDR'];

// Remove < and > from the email message.
$msg = str_replace("<","",$msg);
$msg = str_replace(">","",$msg);

// Set email variables.
$your_email = 'email@mydomain.com';
$your_name = 'Joe Blogs';
$your_link = 'http://www.mydomain.com/';
$confirm_sub = 'Message Sent';

$confirm_msg = "Hi $feedbackname,

Thank you for your email message sent from the $sub.

I will respond to it as quickly as I can.

Thanks again,

$your_name

$your_link";

$contact_msg = "$feedbackname ($feedbackemail) wrote:
$msg

$ip";

// Begin the sendmail routine.
if ($send) {
if (!$feedbackname || !$feedbackemail || substr_count($feedbackemail, '@') < 1 || 
substr_count($feedbackemail, '.') < 1 || !$sub || !$msg || substr_count($spam, 'clark') < 1) {
   print <<<EOF
<html>
<title>Error!</title>
<body background="$back" bgcolor="$bg" text=$text link=$link 
vlink=$vlink transition=$trans fontsize=medium>
<center>
<br><br>
<font s=7 c=f0><b>
Error!</b></font>
<p>
Please go back and correct the errors listed below:
<p>
<table>
<tr><td>
<ul>
EOF;

if (!$feedbackname) {
   print "<li>Your name is missing!<br>"; }
if (!$feedbackemail || substr_count($feedbackemail, '@') < 1 || substr_count($feedbackemail, '.') < 1) {
   print "<li>Your email is missing or invalid!<br>"; }
if (!$sub) {
   print "<li>The email subject is missing!<br>"; }
if (!$msg) {
   print "<li>The email message is missing!"; }
if (substr_count($spam, 'clark') < 1) {
print "You need to correctly type in the Anti-Spam word. Hit Back and try again."; }

   print <<<EOF
</ul>
</table>
<p>
<A href="feedback.php">Back</A>
<br><br><br><br>
</center>
</body>
</html>
EOF;
}
else {

// Email that gets sent to you.
mail($your_email, $sub, $contact_msg, "From: $feedbackname < $feedbackemail >");

// Email that gets sent to them.
mail($feedbackemail, $confirm_sub, $confirm_msg, "From: $your_email");

// Print the thank you page.
   print <<<EOF
<html>
<head><title>Message Sent</title>
</head>
<body background="$back" bgcolor="$bg" text=$text link=$link vlink=$vlink transition=$trans>
<H2>Feedback</H2>

Thanks $feedbackname for sending your message to me!<P>

You will receive a confirmation email momentarily.<P>

</body>
</html>
EOF;
}
}
else {

// Print the contact form page.
   print <<<EOF
<H3>Feedback Form</H3>

To send an email to me simply fill out the form below.<P>

<form method=post>

Name: <input name=feedbackname $txtbxtag size=40><P>

Email: <input name=feedbackemail $txtbxtag size=40><P>

<INPUT type="hidden" name="sub" value="Feedback Form">

Message:<br>
<textarea name=msg rows=10 cols=50 maxlength=500 
$txtbxtag></textarea><P>

<IMG SRC="images/sh-layout/turing.jpg" WIDTH="100" HEIGHT="30" BORDER="0" ALT="turing"><BR>
Anti-Spam Measure - In lowercase letters, retype the word in the image above:<BR>
<input name=spam $txtbxtag size=40><P>

<INPUT TYPE=submit NAME=send $BTNTAG VALUE="Send"><BR>
</form>

EOF;
}

?>

 

Link to comment
Share on other sites

Your code is relying on something that was turned off by default 9 years ago. I won't mention the setting so that you won't be temped to turn it on, because it is scheduled to be completely removed from the next major php version release.

 

It's time to fix your code. You are experting your form's $_POST data to magically appear in php variables, i.e. $msg, $feedbackname, ... You need to to either use $_POST['msg'], $_POST['feedbackname'], ... in your code or you need to set the php variables from the corresponding $_POST variables - $msg = $_POST['msg']; (repeat for each form field name.)

 

If you debug your code with error_reporting set to E_ALL and display_errors set to ON, you will be getting undefined error messages for each php variable name that you need to fix.

 

You should also get in the habit of using full opening php tags <?php so that your code doesn't stop working when you try it on servers that don't support the short <? php tag.

Link to comment
Share on other sites

For the variable stuff just assign the variables, as you have the other ones at the start of the page, to whatever the corresponding input name is in the form that is posting the information through to this page.  As for the error reporting, you would be best to edit this in the php.ini file and then restart your http server.  there are instructions in the php.ini file ate the relevent location, also you can google how to turn on error reporting in php.ini for further guides.

Link to comment
Share on other sites

I'm not proficient enough with PHP to know how to do that. Is there any chance someone could help?

 

Here's a step by step explanation.

 

You are experting your form's $_POST data to magically appear in php variables

You cannot call a POST or GET value by just typing in a variable. Let's say that your POST field is $feedbackemail. Nowhere in your code is $feedbackemail specified. If your input field is named feedbackemail, you must use the syntax $_POST['feedbackemail'].

 

If you debug your code with error_reporting set to E_ALL and display_errors set to ON, you will be getting undefined error messages for each php variable name that you need to fix.

Add this to the top of the page, just after your opening tag (<?php):

ini_set("error_reporting", "true");

error_reporting(E_ALL|E_STRCT);

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.