This repository has been archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
template-contact.php
218 lines (169 loc) · 5.58 KB
/
template-contact.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* Template Name: Contact
* The template for displaying the contact template.
*
* @package Trim
* @link https://themebeans.com/themes/trim
*/
get_header();
// PAGE META
$page_title = get_post_meta( $post->ID, '_bean_page_title', true );
$page_layout = get_post_meta( $post->ID, '_bean_page_layout', true );
// CONTACT CODE
if ( isset( $_POST['submitted'] ) ) {
if ( trim( $_POST['contactName'] ) === '' ) {
$hasError = true;
} else {
$name = trim( $_POST['contactName'] );
}
if ( trim( $_POST['email'] ) === '' ) {
$hasError = true;
} elseif ( ! is_email( trim( $_POST['email'] ) ) ) {
$hasError = true;
} else {
$email = trim( $_POST['email'] );
}
if ( trim( $_POST['comments'] ) === '' ) {
$hasError = true;
} else {
if ( function_exists( 'stripslashes' ) ) {
$comments = stripslashes( trim( $_POST['comments'] ) );
} else {
$comments = trim( $_POST['comments'] );
}
}
if ( ! isset( $hasError ) ) {
$site_name = get_bloginfo( 'name' );
$contactEmail = get_theme_mod( 'admin_custom_email', trim_defaults( 'admin_custom_email' ) );
if ( ! isset( $contactEmail ) || ( $contactEmail == '' ) ) {
$contactEmail = get_option( 'admin_email' );
}
$subject = '[' . $site_name . ' Contact Form] ';
$body = "Name: $name \n\nEmail: $email \n\nMessage: $comments";
$headers = 'Reply-To: ' . $email;
/*
By default, this form will send from [email protected] in order to work with
a number of web hosts' anti-spam measures. If you want the from field to be the
user sending the email, please uncomment the following line of code.
*/
// $headers = 'From: '.$name.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;
wp_mail( $contactEmail, $subject, $body, $headers );
$emailSent = true;
}
} ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( "single-page $page_layout" ); ?>>
<?php if ( get_theme_mod( 'google_maps_code', trim_defaults( 'google_maps_code' ) ) ) { ?>
<div class="entry-content-media g-map">
<?php echo get_theme_mod( 'google_maps_code', trim_defaults( 'google_maps_code' ) ); ?>
</div><!-- END .g-map -->
<?php
} else {
if ( ( function_exists( 'has_post_thumbnail' ) ) && ( has_post_thumbnail() ) ) {
?>
<div class="entry-content-media">
<?php the_post_thumbnail( 'post-feat' ); ?>
</div><!-- END .entry-content-media -->
<?php
} //END if ( (function_exists('has_post_thumbnail'))
}
?>
<div class="inner">
<div class="entry-content">
<?php
if ( $page_title == 'on' ) {
?>
<h1 class="entry-title"><?php the_title( '' ); ?></h1><?php } ?>
<?php
while ( have_posts() ) :
the_post();
the_content();
endwhile; // THE LOOP
?>
<?php if ( get_theme_mod( 'bean_contact_form', trim_defaults( 'bean_contact_form' ) ) == true ) { // IF CONTACT FORM IS TRUE VIA CUSTOMIZER ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#BeanForm").validate({ errors: { contactName: '', email: { required: '', email: '' }, comments: '' } });
});
</script>
<?php if ( isset( $emailSent ) && $emailSent == true ) { ?>
<div class="contact-alert success">
<?php _e( 'Awesome! Your message has been sent!', 'trim' ); ?>
</div><!-- END .alert alert-success -->
<?php } // END SUCCESS ALERT ?>
<?php if ( isset( $hasError ) || isset( $captchaError ) ) { ?>
<div class="contact-alert fail">
<?php _e( 'Well now... an error occured. Please try again.', 'trim' ); ?>
</div><!-- END .alert alert-success -->
<?php } // END FAIL ALERT ?>
<?php $required = '<span class="required">*</span>'; ?>
<form action="<?php the_permalink(); ?>" id="BeanForm" method="post">
<ul class="bean-contactform">
<li class="name">
<label for="contactName">
<?php
_e( 'Name', 'trim' );
echo $required;
?>
</label>
<input type="text" name="contactName" id="contactName" value="
<?php
if ( isset( $_POST['contactName'] ) ) {
echo $_POST['contactName'];}
?>
" class="required requiredField" />
</li>
<li class="email">
<label for="email">
<?php
_e( 'Email', 'trim' );
echo $required;
?>
</label>
<input type="text" name="email" id="email" value="
<?php
if ( isset( $_POST['email'] ) ) {
echo $_POST['email'];}
?>
" class="required requiredField email" />
</li>
<li class="textarea"><label for="commentsText">
<?php
_e( 'Message', 'trim' );
echo $required;
?>
</label>
<textarea name="comments" id="commentsText" rows="20" cols="30" class="required requiredField">
<?php
if ( isset( $_POST['comments'] ) ) {
if ( function_exists( 'stripslashes' ) ) {
echo stripslashes( $_POST['comments'] );
} else {
echo $_POST['comments']; }
}
?>
</textarea>
</li>
<li class="submit">
<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit" class="button"><?php echo get_theme_mod( 'contact_button_text', trim_defaults( 'contact_button_text' ) ); ?></button>
</li>
</ul>
</form><!-- END #BeanForm -->
<?php } ?>
<?php
wp_link_pages(
array(
'before' => '<div class="page-link"><span>' . __( 'Pages:', 'trim' ) . '</span>',
'after' => '</div>',
)
);
?>
</div><!-- END .entry-content -->
</div><!-- END .inner -->
</article>
<?php
if ( $page_layout === 'page_sidebar' or $page_layout === 'page_fullwidth_sidebar' ) {
dynamic_sidebar( 'internal-sidebar' );
}
get_footer();