Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.96 KB | None | 0 0
  1. <?php
  2. /* Template Name: Inschrijven */
  3.  
  4. $context = Timber::get_context();
  5. $post = new TimberPost();
  6. $context['post'] = $post;
  7.  
  8. if(isset($_GET['cursus_name'])){
  9.     $context['cursus_name'] = $_GET['cursus_name'];
  10. //    dd($context['cursus_name']);
  11. }
  12.  
  13. if(isset($_GET['workshop_name']) && isset($_GET['date'])){
  14.     $context['workshop_name'] = 'Naam: '. $_GET['workshop_name']. ' ,Datum: '.$_GET['date'];
  15. }
  16.  
  17. $args = [
  18.     'post_type' => 'course',
  19.     'posts_per_page' => -1,
  20. ];
  21.  
  22. //Get courses for form
  23. $context['courses'] = Timber::get_posts($args);
  24.  
  25. //Sets error array for form
  26. $context['errors'] = [];
  27.  
  28. //Validation for form
  29. if(isset($_POST['submit'])){
  30.     if(empty($_POST['titulature'])){
  31.         $context['errors']['titulature'] = 'Vul uw titelatuur in';
  32.     } else {
  33.         $context['form']['titulature'] = $_POST['titulature'];
  34.     }
  35.     if(empty($_POST['initials'])){
  36.         $context['errors']['initials'] = 'Vul uw voorletters in';
  37.     } else {
  38.         $context['form']['initials'] = $_POST['initials'];
  39.     }
  40.     if(empty($_POST['firstName'])){
  41.         $context['errors']['firstName'] = 'Vul uw voornaam in';
  42.     } else {
  43.         $context['form']['firstName'] = $_POST['firstName'];
  44.     }
  45.     if(empty($_POST['lastName'])){
  46.         $context['errors']['lastName'] = 'Vul uw achternaam in';
  47.     } else {
  48.         $context['form']['lastName'] = $_POST['lastName'];
  49.     }
  50.     if(empty($_POST['birthDate'])){
  51.         $context['errors']['birthDate'] = 'Vul uw geboortedatum in';
  52.     } else {
  53.         $context['form']['birthDate'] = $_POST['birthDate'];
  54.     }
  55.     if(empty($_POST['birthPlace'])){
  56.         $context['errors']['birthPlace'] = 'Vul uw geboorteplaats in';
  57.     } else {
  58.         $context['form']['birthPlace'] = $_POST['birthPlace'];
  59.     }
  60.     if(empty($_POST['street'])){
  61.         $context['errors']['street'] = 'Vul uw straat in';
  62.     } else {
  63.         $context['form']['street'] = $_POST['street'];
  64.     }
  65.     if(empty($_POST['houseNumber'])){
  66.         $context['errors']['houseNumber'] = 'Vul uw huisnummer in';
  67.     } else {
  68.         $context['form']['houseNumber'] = $_POST['houseNumber'];
  69.     }
  70.     if(empty($_POST['addition'])){
  71.         $context['form']['addition'] = '';
  72.     } else {
  73.         $context['form']['addition'] = $_POST['addition'];
  74.     }
  75.     if(empty($_POST['zipcode'])){
  76.         $context['errors']['zipcode'] = 'Vul uw postcode in';
  77.     } else {
  78.         $context['form']['zipcode'] = $_POST['zipcode'];
  79.     }
  80.     if(empty($_POST['place'])){
  81.         $context['errors']['place'] = 'Vul uw plaats in';
  82.     } else {
  83.         $context['form']['place'] = $_POST['place'];
  84.     }
  85.     if(empty($_POST['phoneNumber'])){
  86.         $context['errors']['phoneNumber'] = 'Vul uw telefoonnnummer in';
  87.     } else {
  88.         $context['form']['phoneNumber'] = $_POST['phoneNumber'];
  89.     }
  90.     if(empty($_POST['email'])){
  91.         $context['errors']['email'] = 'Vul uw email in';
  92.     } else {
  93.         $context['form']['email'] = $_POST['email'];
  94.     }
  95.    
  96.     //1
  97.     // if (empty($_POST['course']) && empty($_POST['cursus']) && empty($_POST['workshop'])) {
  98.     //     $context['errors']['schooling'] = 'Je moet minimaal 1 opleiding, cursus of workshop selecteren';
  99.     // }
  100.    
  101.     // if (!empty($_POST['course']) && empty($_POST['payment'])) {
  102.     //     $context['errors']['payment'] = 'Voor een opleiding dient u een betalingskeuze te maken.';
  103.     // }
  104.    
  105.     // $context['form']['payment'] = $_POST['payment'] ?: '';
  106.     // $context['form']['course'] = $_POST['course'] ?: '';
  107.     // $context['form']['cursus'] = $_POST['cursus'] ?: '';
  108.     // $context['form']['workshop'] = $_POST['workshop'] ?: '';
  109.    
  110.     //2
  111.     // if (empty($_POST['course']) && empty($_POST['cursus']) && empty($_POST['workshop'])) {
  112.     //     $context['errors']['schooling'] = 'Je moet minimaal 1 opleiding, cursus of workshop selecteren';
  113.     // }
  114.    
  115.     // if (!empty($_POST['course']) && empty($_POST['payment'])) {
  116.     //     $context['errors']['payment'] = 'Voor een opleiding dient u een betalingskeuze te maken.';
  117.     // }
  118.    
  119.     // else if (!empty($_POST['course']) && !empty($_POST['payment'])) {
  120.     //     $context['form']['payment'] = $_POST['payment'];
  121.     //     $context['form']['course'] = $_POST['course'];
  122.     // }
  123.  
  124.     // if (!empty($_POST['cursus'])) {
  125.     //     $context['form']['cursus'] = $_POST['cursus'];
  126.     // }
  127.    
  128.     // if (!empty($_POST['workshop'])) {
  129.     //     $context['form']['workshop'] = $_POST['workshop'];
  130.     // }
  131.  
  132.     $context['form']['payment'] = $_POST['payment'] ?: '';
  133.     $context['form']['course'] = $_POST['course'] ?: '';
  134.     $context['form']['cursus'] = $_POST['cursus'] ?: '';
  135.     $context['form']['workshop'] = $_POST['workshops'] ?: '';
  136.      
  137.     if(!empty($_POST['course'])){
  138.         if(empty($_POST['payment'])){
  139.             $context['errors']['payment'] = 'Voor een opleiding dient u een betalingswijze te kiezen.';
  140.         }
  141.     }
  142.     elseif(empty($_POST['cursus']) && empty($_POST['workshops'])){
  143.         $context['errors']['schooling'] = 'Je moet minimaal 1 opleiding, cursus of workshop selecteren';
  144.     }
  145.  
  146.     if(empty($_POST['comment'])){
  147.         $context['form']['comment'] = '-';
  148.     } else {
  149.         $context['form']['comment'] = $_POST['comment'];
  150.     }
  151.     if(empty($_POST['terms'])){
  152.         $context['errors']['terms'] = 'Om u te kunnen inschrijven moet u akkoord gaan met de algemene voorwaardem.';
  153.     } else {
  154.         $context['form']['terms'] = implode(',',$_POST['terms']);
  155.     }
  156.     if(count($context['errors']) == 0){
  157.         sendTemplateMail('mail/signup.twig', $context['form'], 'Uw inschrijving', 'info@school4us.nl', $context['form']['email']);
  158.         sendTemplateMail('mail/signup_client.twig', $context['form'], 'Inschrijving van '.$context['form']['firstName'].' '.$context['form']['lastName'], $context['form']['email'], 'info@school4us.nl');
  159.         $context['success'] = 'Uw mail is verstuurd.';
  160.     }
  161. }
  162.  
  163. Timber::render('pages/page-signup.twig', $context );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement