Combined Feedback Form : Form Post « Form « PHP

Home
PHP
1.Chart
2.Class
3.Components
4.Cookie Session
5.Data Structure
6.Data Type
7.Date
8.Design Patterns
9.Development
10.DNS
11.Email
12.File Directory
13.Form
14.Functions
15.Graphics Image
16.HTML
17.Language Basics
18.Login Authentication
19.Math
20.MySQL Database
21.Network
22.Operator
23.PDF
24.Reflection
25.Statement
26.String
27.Utility Function
28.Web Services SOAP WSDL
29.XML
PHP » Form » Form Post 
Combined Feedback Form
 
<html>
<head><title>Combined Feedback Form</title></head>
<body>

<?php

$self = $_SERVER['PHP_SELF'];
$username = $_POST['username'];
$useraddr = $_POST['useraddr'];
$comments = $_POST['comments'];
$sent = $_POST['sent'];

$form ="<form action=\"$self\" method=\"post\">";
$form.="Name:<input type=\"text\" name=\"username\"";
$form.=" size=\"30\" value=\"$username\" >";
$form.="Email:<input type=\"text\" name=\"useraddr\"";
$form.=" size=\"30\" value=\"$useraddr\">";
$form.="Comments:<textarea name=\"comments\" >";
$form.="$comments</textarea><br/>";
$form.="<input type=\"submit\" name=\"sent\" value=\"Send Form\">";
$form.="</form>";

if($sent)
{
  $valid=true;

  if!$username )
  $errmsg.="Enter your name...<br />"; $valid = false}

  if!$useraddr )
  $errmsg .="Enter your email address...<br />"; $valid = false}

  if!$comments )
  $errmsg.="Enter your comments...<br />"; $valid = false}

  $useraddr = trim($useraddr);
  $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}~]+";
  $_host = "([-0-9A-Z]+\.)+";
  $_tlds = "([0-9A-Z]){2,4}$/i";
  if!preg_match$_name."@".$_host .$_tlds,$useraddr ) )
  
    $errmsg.="Email address has incorrect format!<br />";
    $valid=false;
  }
}

if($valid != true)
{
  echo$errmsg.$form );
}
else
{
  $to = "[email protected]";

  $re = "Feedback from $username";

  $msg = $comments;

  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html;";   
  $headers .= "charset=\"iso-8859-1\"\r\n";

  $headers .= "From: $useraddr \r\n";

  if(mail($to,$re,$msg, $headers))
  echo("Your comments have been sent - thanks $username");}

}
?>

</body></html>
  
  
Related examples in the same category
1.An HTML Form That Calls Itself
2.Form submitting
3.GET vs. POST
4.Making a multipage form
5.One-script form processing
6.Preventing Multiple Submissions on the Client Side
7.Preventing Multiple Submissions on the Server Side
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.