Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("php/db.php"); /* Database Class */
- require_once('php/utils/is_email.php'); /* Email Validation Script */
- if(!empty($_POST['newcontact'])){
- $contact = new Contact();
- } else{
- //header('Location: result.php');
- }
- /* Class Contact */
- class Contact
- {
- private $db; /* the database obj */
- //we have to init $errors array, as otherwise form will produce errors on missing array entry
- private $errors = array( /* holds error messages */
- 'aanhef' => '',
- '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 = "<div style=\"font-size:12px; font-weight:normal;\">Hallo,<br><br>"
- ."Het volgende bedrijf heeft zich zojuist aangemeld voor de Veiligheids Quiz:</div><br>"
- ."<table cellpadding=\"1\" cellspacing=\"1\" width=\"550px\"><tr><td style=\"font-size:12px; color:#000000\">Bedrijfsnaam:</td><td style=\"font-size:12px; color:#000000\">".$bedrijfsnaam."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Aanhef:</td><td style=\"font-size:12px; color:#000000\">".$aanhef."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Contactpersoon:</td><td style=\"font-size:12px; color:#000000\">".$contactpersoon."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Telefoonnummer:</td><td style=\"font-size:12px; color:#000000\">".$telefoon."</td></tr><tr><td style=\"font-size:12px; color:#000000\">E-mail:</td><td style=\"font-size:12px; color:#000000\">".$email."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Antwoord vraag 1:</td><td style=\"font-size:12px; color:#000000\">".$vraag1_antwoorden."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Antwoord vraag 2:</td><td style=\"font-size:12px; color:#000000\">".$vraag2_antwoorden."</td></tr></table><br>";
- // Geef GELDIGE adressen op
- // Een korte benaming voor jouw website
- $website_naam = 'Aanmelding Quiz';
- // Jouw eigen geldige emailadres
- $eigen_emailadres = 'MY MAIL';
- // Een geldig emailadres voor errors
- $error_emailadres = 'MY MAIL';
- // De naam van de verzender
- $naam_verzender = ''.$bedrijfsnaam.'';
- // Het geldige emailadres van de afzender
- $email_verzender = ''.$email.'';
- // Een geldig emailadres of helemaal leeg laten
- $bcc_emailadres = '';
- // HTML mail? True/False
- $html = true;
- // De headers samenstellen
- $headers = 'From: ' . $website_naam . ' <' . $eigen_emailadres . '>' . PHP_EOL;
- $headers .= 'Reply-To: ' . $naam_verzender . ' <' . $email_verzender . '>' . PHP_EOL;
- $headers .= 'Return-Path: Mail-Error <' . $error_emailadres . '>' . PHP_EOL;
- $headers .= ($bcc_emailadres != '') ? 'Bcc: ' . $bcc_emailadres . PHP_EOL : '';
- $headers .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
- $headers .= 'X-Priority: Normal' . PHP_EOL;
- $headers .= ($html) ? 'MIME-Version: 1.0' . PHP_EOL : '';
- $headers .= ($html) ? 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL : '';
- mail(EMAIL_TO,MESSAGE_SUBJECT,$message_body,$headers);
- }
- public function setError($field, $errmsg)
- {
- $this->has_errors = true;
- $this->errors[$field] = $errmsg;
- }
- public function errors($field)
- {
- if (array_key_exists($field,$this->errors)){
- return $this->errors[$field];
- }
- return '';
- }
- };
- ?>
- <table width="675px" cellpadding="0" cellspacing="0">
- <form id="contact_form" method="post" action="">
- <label class="label_aanhef" for="aanhef_1"><input name="aanhef" id="aanhef_1" type="radio" value="Dhr." /> Dhr.</label><label class="label_aanhef" for="aanhef_2"><input name="aanhef" id="aanhef_2" type="radio" value="Mevr." /> Mevr.</label>
- <span class="error"><?php echo $contact->errors('aanhef'); ?></span>
- <input id="contactpersoon" name="contactpersoon" maxlength="120" type="text" onFocus="window.scrollTo(0, 0);"/><span class="error"><?php echo $contact->errors('contactpersoon'); ?></span>
- <input id="bedrijfsnaam" name="bedrijfsnaam" maxlength="120" type="text" onFocus="window.scrollTo(0, 0);"/><span class="error"><?php echo $contact->errors('bedrijfsnaam'); ?></span>
- <input id="email" name="email" maxlength="120" type="text" onFocus="window.scrollTo(0, 0);"/><span class="error"><?php echo $contact->errors('email'); ?></span>
- <input id="telefoon" name="telefoon" maxlength="120" type="text" onFocus="window.scrollTo(0, 0);"/><span class="error"><?php echo $contact->errors('telefoon'); ?></span>
- <label class="label_radio" for="vraag1_A"><input name="vraag1_antwoorden" id="vraag1_A" value="A. Dat is helaas fout, het goede antwoord is: C) < 1 Ohm" type="radio" />A) Geen eis</label>
- <label class="label_radio" for="vraag1_B"><input name="vraag1_antwoorden" id="vraag1_B" value="B. Dat is helaas fout, het goede antwoord is: C) < 1 Ohm" type="radio" />B) < 0,1 Ohm</label>
- <label class="label_radio" for="vraag1_C"><input name="vraag1_antwoorden" id="vraag1_C" value="C. Gefeliciteerd dat is het goede antwoord." type="radio" />C) < 1 Ohm</label>
- <label class="label_radio" for="vraag1_D"><input name="vraag1_antwoorden" id="vraag1_D" value="D. Dat is helaas fout, het goede antwoord is: C) < 1 Ohm" type="radio" />D) < 10 Ohm</label>
- <span id="vraag1_antwoorden" class="foutmelding_quiz">
- <?php echo $contact->errors('vraag1_antwoorden'); ?>
- </span>
- <label class="label_radio" for="vraag2_A"><input name="vraag2_antwoorden" id="vraag2_A" value="A. Gefeliciteerd dat is het goede antwoord." type="radio" />A) Geen eis</label>
- <label class="label_radio" for="vraag2_B"><input name="vraag2_antwoorden" id="vraag2_B" value="B. Dat is helaas fout, het goede antwoord is: A) Geen eis" type="radio" />B) < 0,1 Ohm</label>
- <label class="label_radio" for="vraag2_C"><input name="vraag2_antwoorden" id="vraag2_C" value="C. Dat is helaas fout, het goede antwoord is: A) Geen eis" type="radio" />C) < 1 Ohm</label>
- <label class="label_radio" for="vraag2_D"><input name="vraag2_antwoorden" id="vraag2_D" value="D. Dat is helaas fout, het goede antwoord is: A) Geen eis" type="radio" />D) < 10 Ohm</label>
- <span id="vraag2_antwoorden" class="foutmelding_quiz">
- <?php echo $contact->errors('vraag2_antwoorden'); ?>
- </span>
- <input class="button submit" type="submit" value="" /><input id="newcontact" name="newcontact" type="hidden" value="1"></input>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement