Guest User

Contact form processing code

a guest
Jan 27th, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. <?php
  2.  
  3. // Include required functions.
  4. require_once ("php/_functions/send_mail.php");
  5.  
  6. // Prepare necessary variables for later use.
  7. $Page = "_contact_form";
  8.  
  9. // Check if page was submitted, and within time.
  10. if (Check_Submit ($Template->BUTTON_SUBMIT, 600)) {
  11.     // Was, prepare necessary variables for later use.
  12.     $Message = array ();
  13.  
  14.     // Validate input variables.
  15.     $Name = Validate ('name', 'name', 'NAME', 'FORM_NAME', $Message, 60, "æøåÆØÅöÖäÄéá");
  16.     $Email = Validate ('email', 'email', 'EMAIL', 'FORM_EMAIL', $Message);
  17.     $Comments = Validate ('string', 'message', 'MESSAGE', 'FORM_MESSAGE', $Message, "+", "\r\n.?!:;,/'\"%@æøåÆØÅöÖäÄ_£€$");
  18.  
  19.     // Check to see if everything validated correctly.
  20.     if (!empty ($Message)) {
  21.         // Didn't, prepare the error message for display, and stop processing.
  22.         $Message = "<ul>\n\t<li>".implode ("</li>\n\t<li>", $Message)."</li>\n</ul>\n";
  23.         $Template->_MESSAGE = '<p id="form_error" class="message error">'.sprintf ($Template->ERROR_FORM, $Message)."</p>\n";
  24.         return;
  25.     }
  26.  
  27.     // Send mail to site owner.
  28.     Send_Mail ($Name, $Email, $Template->MAIL_CONTACT_SUBJECT, $Comments);
  29.  
  30.     // Succeeded, send to "OK" page and prevent F5-resend.
  31.     header ("Location: {$Template->_PHP_SELF}send=ok");
  32.     die ();
  33. }
  34.  
  35. // Check if form was submitted at all.
  36. if (Check_Submit ($Template->BUTTON_SUBMIT)) {
  37.     // Wasn't submitted within time limit, show warning and populate fields with submitted data.
  38.     $Template->_FORM_FIELD_NAME = htmlspecialchars ($_POST['name']);
  39.     $Template->_FORM_FIELD_EMAIL = htmlspecialchars ($_POST['email']);
  40.     $Template->_FORM_FIELD_MESSAGE = htmlspecialchars ($_POST['message']);
  41.     $Template->_MESSAGE = '<p id="form_error" class="message error">'.$Template->ERROR_TIME_EXPIRED."</p>\n";
  42.     unset ($_GET['send']);
  43. }
  44.  
  45. // Check if submission was completed successfully.
  46. if ($_GET['send'] == "ok") {
  47.     // Mail was sent successfully, and it's time to display the "OK" message.
  48.     $Template->_MESSAGE = '<p id="form_error" class="message green">'.$Template->MAIL_SUBMITTED."</p>\n";
  49. }
Advertisement
Add Comment
Please, Sign In to add comment