'', 'contactpersoon' => '', 'bedrijfsnaam' => '', 'email' => '', 'telefoon' => '', 'vraag1_antwoorden' => '', 'vraag2_antwoorden' => '' ); private $has_errors; /* number of errors in submitted form */ public function __construct() { $this->db = new DB(); if (!empty($_POST['newcontact'])) { $this->processNewMessage(); } } public function processNewMessage() { $aanhef = $_POST['aanhef']; $contactpersoon = $_POST['contactpersoon']; $bedrijfsnaam = $_POST['bedrijfsnaam']; $telefoon = $_POST['telefoon']; $email = $_POST['email']; $vraag1_antwoorden = $_POST['vraag1_antwoorden']; $vraag2_antwoorden = $_POST['vraag2_antwoorden']; /* Server Side Data Validation */ if (empty($aanhef)) { $this->setError('aanhef', 'Vul uw aanhef in'); } if (empty($contactpersoon)) { $this->setError('contactpersoon', 'Vul uw contactpersoon in'); } if (empty($bedrijfsnaam)) { $this->setError('bedrijfsnaam', 'Vul uw bedrijfsnaam in'); } if (empty($telefoon)) { $this->setError('telefoon', 'Vul uw telefoon in'); } if (empty($vraag1_antwoorden)) { $this->setError('vraag1_antwoorden', 'Selecteer een antwoord a.u.b.'); } if (empty($vraag2_antwoorden)) { $this->setError('vraag2_antwoorden', 'Selecteer een antwoord a.u.b.'); } if (empty($email)) { $this->setError('email', 'Vul uw e-mail in'); } /* No errors, insert in db else*/ if(!$this->has_errors) { if(($ret = $this->db->dbNewMessage($aanhef, $contactpersoon, $bedrijfsnaam, $email, $telefoon, $vraag1_antwoorden, $vraag2_antwoorden)) > '') { //$json = array('result' => 1); if (SEND_EMAIL) { $this->sendEmail($aanhef,$contactpersoon,$bedrijfsnaam,$email,$telefoon,$vraag1_antwoorden,$vraag2_antwoorden); //This is for relocating to successful result page header('Location: result.php'); exit; } else { //This will need special treatment. You have to prepare an errorpage //for database-related issues. header("Location: database-error.html"); exit; } } } } public function sendEmail($aanhef,$contactpersoon,$bedrijfsnaam,$email,$telefoon,$vraag1_antwoorden,$vraag2_antwoorden) { /* Just format the email text the way you want ... */ $message_body = "
Bedrijfsnaam: | ".$bedrijfsnaam." |
Aanhef: | ".$aanhef." |
Contactpersoon: | ".$contactpersoon." |
Telefoonnummer: | ".$telefoon." |
E-mail: | ".$email." |
Antwoord vraag 1: | ".$vraag1_antwoorden." |
Antwoord vraag 2: | ".$vraag2_antwoorden." |