-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathenquiries-template.php
132 lines (111 loc) · 4.79 KB
/
enquiries-template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/*
Template Name: Enquiries
*/
if($_POST){
var_dump($_POST);
$errors = array();
if(!wp_verify_nonce($_POST['_wpnonce'], 'wp_enquiery_form')){
array_push($errors, 'Sorry something went wrong with processing this form, Please try again');
} else {
if(!$_POST['enquiriesName']){
array_push($errors, "Your name is required, please enter a value");
} else if(strlen($title) < 2){
array_push($errors, "Please enter at least 2 characters for your Name");
}
$content = $_POST['enquiriesMessage'];
if(!$_POST['enquiriesMessage']){
array_push($errors, "A message is required, please enter a value");
} else if(strlen($_POST['enquiriesMessage']) < 10){
array_push($errors, "Please enter at least 10 characters for your Message");
}
if(!$_POST['enquiriesEmail']){
array_push($errors, "An Email is required, please enter a value");
} else if(!filter_var($_POST['enquiriesEmail'], FILTER_VALIDATE_EMAIL)){
array_push($errors, "Please enter a valid email address");
}
if(!$_POST['enquiriesCourseInterest']){
array_push($errors, "Please select a Course you are intereted in.");
} else if($_POST['enquiriesCourseInterest'] === ''){
array_push($errors, "Please select a Course you are intereted in.");
}
if(empty($errors)){
$args = array(
'post_title' => $_POST['enquiriesName'],
'post_content' => $_POST['enquiriesMessage'],
'post_type' => 'enquiries',
'meta_input' => array(
'email' => $_POST['enquiriesEmail'],
'courseInterest' => $_POST['enquiriesCourseInterest']
)
);
wp_insert_post($args);
echo "Your Enquiry has been sent";
}
}
}
?>
<?php get_header(); ?>
<?php if(have_posts()): ?>
<?php while(have_posts()): the_post(); ?>
<div class="container">
<div class="row">
<div class="col">
<h1><?php the_title(); ?></h1>
</div>
</div>
<div class="row">
<div class="col">
<div class="wp_content">
<?php the_content(); ?>
</div>
</div>
</div>
<?php if($_POST && !empty($errors)): ?>
<div class="row mb-2">
<div class="col">
<div class="alert alert-danger pb-0" role="alert">
<ul>
<?php foreach($errors as $singleError): ?>
<li><?= $singleError; ?></li>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col">
<form action="<?= get_permalink(); ?>" method="post">
<?php wp_nonce_field('wp_enquiery_form'); ?>
<div class="form-group">
<label for="">Name</label>
<input type="text" name="enquiriesName" class="form-control" value="">
</div>
<div class="form-group">
<label for="">Message</label>
<?php wp_editor($content, 'enquiriesMessage', array('textarea_rows' => '10')); ?>
</div>
<div class="form-group">
<label for="">Email</label>
<input type="email" name="enquiriesEmail" class="form-control" value="">
</div>
<div class="form-group">
<label for="">What Course are you interested In</label>
<select class="form-control" name="enquiriesCourseInterest">
<option value="">Choose a Course</option>
<option value="Course1">Course 1</option>
<option value="Course2">Course 2</option>
<option value="Course3">Course 3</option>
</select>
</div>
<div class="form-group">
<input type="submit" name="" value="Send Enquiry" class="btn btn-primary btn-block">
</div>
</form>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>