Jump to content


Photo

Please help on my simple feedback form....


  • Please log in to reply
4 replies to this topic

#1 joseph

joseph
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 03 July 2006 - 11:23 AM

Is there anything wrong with this code?? I've recevied the feedback when I opend my email, but it only showed the input contained in "$Other" and "$Feedback"! and the email went straigt to the bulk mail. Please help....

PHP code "feedback.php"
<?php
if (!isset($_POST['Submit'])) {
   echo "<h1>Error</h1>\n
      <p>Accessing this page directly is not allowed.</p>";
   exit;
}

function cleanUp($data) {
   $data = strip_tags($data);
   $data = trim(htmlentities($data));
   return $data;
}

$title        = cleanUp($_POST['mr']);
$title        = cleanUp($_POST['mrs']);
$title        = cleanUp($_POST['ms']);
$FirstName      = cleanUp($_POST['txtFirstName']);
$LastName     = cleanUp($_POST['txtLastName']);
$Email       = cleanUp($_POST['txtEmail']);
$URL         = cleanUp($_POST['txtURL']);
$Country     = cleanUp($_POST['menuCountry']);
$connSpeed       = cleanUp($_POST['28kbps']);
$connSpeed       = cleanUp($_POST['56kbps']);
$connSpeed       = cleanUp($_POST['dsl']);
$connSpeed       = cleanUp($_POST['t1']);
$Concerning  = cleanUp($_POST['menuConcerning']);
$Other      = cleanUp($_POST['txtOther']);
$Feedback   = cleanUp($_POST['txtFeedback']);
$Contact    = cleanUp($_POST['yes']);


if ((empty($FirstName)) || (empty($LastName)) || (empty($Email)) || (empty($Concerning)) || (empty($Feedback))) {
   echo "<h2>Input Error</h2>\n
     <p><strong>Name</strong>, <strong>e-mail</strong> and <strong>comments</strong> are required fields. Please fill them in and try again:</p>";

   echo "<form action=\"feedback.php\" method=\"post\"><p>";
   echo "<input type=\"radio\" name=\"title\" id=\"mr\" value=\"$title\" /> Mr<br />";
   echo "<input type=\"radio\" name=\"title\" id=\"mrs\" value=\"$title\" /> Mrs<br />";
   echo "<input type=\"radio\" name=\"title\" id=\"ms\" value=\"$title\" /> Ms<br />";
   echo "<input type=\"text\" name=\"txtFirstName\" id=\"txtFirstName\" value=\"$FirstName\" /> First Name<br />";
   echo "<input type=\"text\" name=\"txtLastName\" id=\"txtLastName\" value=\"$LastName\" /> Last Name<br />";
   echo "<input type=\"text\" name=\"txtEmail\" id=\"txtEmail\" value=\"$Email\" /> Email<br />";
   echo "<input type=\"text\" name=\"txtURL\" id=\"txtURL\"> value=\"$URL\" /> URL<br />";
   echo "<input type=\"text\" name=\"menuCountry\" id=\"Email\" value=\"$Country\" /> Country<br />";
   echo "<input type=\"radio\" name=\"connSpeed\" id=\"28kbps\" value=\"$connSpeed\" /> 28kbps modem<br />";
   echo "<input type=\"radio\" name=\"connSpeed\" id=\"56kbps\" value=\"$connSpeed\" /> 56kbps modem<br />";
   echo "<input type=\"radio\" name=\"connSpeed\" id=\"dsl\" value=\"$connSpeed\" /> DSL<br />";
   echo "<input type=\"radio\" name=\"connSpeed\" id=\"t1\" value=\"$connSpeed\" /> T1 or higher<br />";
   echo "<input type=\"text\" name=\"menuConcerning\" id=\"menuConcerning\" value=\"$Concerning\" /> Concerning<br />";
   echo "<input type=\"text\" name=\"txtOther\" id=\"txtOther\" value=\"$Other\" /> Other<br />";
   echo "<textarea name=\"txtFeedback\" id=\"txtFeedback\">$Feedback</textarea> Feedback<br />";
   echo "<input type=\"checkbox\" name=\"checkboxContact\" id=\"checkboxContact\ value=\"yes\" />";
   echo "<input type=\"Submit\" name=\"Submit\" id=\"Submit\" value=\"Submit\" />";
   echo "</p></form>";

   exit;
}

if (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",$Email)) {
echo "<h2>Input Error</h2>\n
<p>The e-mail address \"$Email\" isn't valid. Please edit it and try again:</p>";

   echo "<form action=\"feedback.php\" method=\"post\"><p>";
   echo "<input type=\"radio\" name=\"title\" id=\"mr\" value=\"$mr\" /> Title<br />";
   echo "<input type=\"radio\" name=\"title\" id=\"mrs\" value=\"$mrs\" /> Title<br />";
   echo "<input type=\"radio\" name=\"title\" id=\"ms\" value=\"$ms\" /> Title<br />";
   echo "<input type=\"text\" name=\"txtFirstName\" id=\"txtFirstName\" value=\"$FirstName\" /> First Name<br />";
   echo "<input type=\"text\" name=\"txtLastName\" id=\"txtLastName\" value=\"$LastName\" /> Last Name<br />";
   echo "<input type=\"text\" name=\"txtEmail\" id=\"txtEmail\" value=\"$Email\" /> Email<br />";
   echo "<input type=\"text\" name=\"txtURL\" id=\"txtURL\"> value=\"$URL\" /> URL<br />";
   echo "<input type=\"text\" name=\"menuCountry\" id=\"Email\" value=\"$Country\" /> Country<br />";
   echo "<input type=\"radio\" name=\"connSpeed\" id=\"28kbps\" value=\"$28kbps\" /> Connection Speed<br />";
   echo "<input type=\"radio\" name=\"connSpeed\" id=\"56kbps\" value=\"$56kbps\" /> Connection Speed<br />";
   echo "<input type=\"radio\" name=\"connSpeed\" id=\"dsl\" value=\"$dsl\" /> Connection Speed<br />";
   echo "<input type=\"radio\" name=\"connSpeed\" id=\"t1\" value=\"$t1\" /> Connection Speed<br />";
   echo "<input type=\"text\" name=\"menuConcerning\" id=\"menuConcerning\" value=\"$Concerning\" /> Concerning<br />";
   echo "<input type=\"text\" name=\"txtOther\" id=\"txtOther\" value=\"$Other\" /> Other<br />";
   echo "<textarea name=\"txtFeedback\" id=\"txtFeedback\">$Feedback</textarea> Feedback<br />";
   echo "<input type=\"checkbox\" name=\"checkboxContact\" id=\"checkboxContact\" value=\"yes\" />";
   echo "<input type=\"Submit\" name=\"Submit\" id=\"Submit\" value=\"Submit\" />";
   echo "</p></form>";

   exit;
}

$Email = preg_replace("([\r\n])", "", $Email);

$find = "/(content-type|bcc:|cc:)/i";
if (preg_match($find, $FirstName) || preg_match($find, $Email) || preg_match($find, $URL) || preg_match($find, $Feedback)) {
   echo "<h1>Error</h1>\n
      <p>No meta/header injections, please.</p>";
   exit;
}

$recipient = "youremail@whatever.com";
$subject   = "Subject here";

$message   = "Title: $title \n";
$message   = "FirstName: $FirstName \n";
$message   = "LastName: $LastName \n";
$message  .= "E-mail: $Email \n";
$message  .= "URL: $URL \n";
$message   = "Country: $Country \n";
$message   = "Connection Speed: $connSpeed \n";
$message   = "Concerning: $Concerning \n";
$message   = "Other: $Other \n";
$message  .= "Feedback: $Feedback";

$headers   = "From: My Form \r\n";
$headers  .= "Reply-To: $Email";

if (mail($recipient,$subject,$message,$headers)) {
   echo "<p>Mail sent successfully.</p>";
} else {
   echo "<p>Mail not sent this time.</p>";
}
?>

Should I post here the html form codes?? Thanks in advance! need help here..

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 03 July 2006 - 01:27 PM

Is there anything wrong with this code??

Plenty. Look at how you put your $message together.
$message   = "Title: $title \n";
$message   = "FirstName: $FirstName \n";
$message   = "LastName: $LastName \n";
$message  .= "E-mail: $Email \n";
$message  .= "URL: $URL \n";
$message   = "Country: $Country \n";
$message   = "Connection Speed: $connSpeed \n";
$message   = "Concerning: $Concerning \n";
$message   = "Other: $Other \n";
$message  .= "Feedback: $Feedback";
Most of these $message variables are just overighting the previous one.

#3 joseph

joseph
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 03 July 2006 - 01:34 PM

Most of these $message variables are just overighting the previous one.

Thanks.. so how do we combine the $message so that it will show all the inputs in the form that will be emailed? and I believe that there is something wrong with my radio declarations. I just started learning php yesterday.

#4 joseph

joseph
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 04 July 2006 - 03:07 AM

so anybody here could help?

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 04 July 2006 - 07:41 AM

when you do this:

$message = "blah";
$message = "xxx";
echo $message;

you get this:

xxx

not this:

blahxxx

if you want this:

blahxxx

you need to do this:

$message = "blah";
$message.= "xxx";
echo $message;

notice the little dot between the e and the =

in your long list of $message = "...."; you conveniently left out that little dot on most of them.  if you had paid attention to thorpe's post, you would have seen that.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users