This repository was archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtemplate-contact.php
More file actions
227 lines (173 loc) · 5.8 KB
/
template-contact.php
File metadata and controls
227 lines (173 loc) · 5.8 KB
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
219
220
221
222
223
224
225
226
227
<?php
/**
* Template Name: Contact
* The template for displaying the contact template.
*
* @package Bricks
* @link https://themebeans.com/themes/bricks
*/
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'] );
}
}
do_action( 'bean_after_contactform_errors' );
if ( ! isset( $hasError ) ) {
$site_name = get_bloginfo( 'name' );
$contactEmail = get_theme_mod( 'admin_custom_email' );
if ( ! isset( $contactEmail ) || ( $contactEmail == '' ) ) {
$contactEmail = get_option( 'admin_email' );
}
$subject_content = '[' . $site_name . ' Contact Form]';
$subject = apply_filters( 'bean_contactform_emailsubject', $subject_content );
$body_content = "Name: $name \n\nEmail: $email \n\nMessage: $comments";
$body = apply_filters( 'bean_contactform_emailbody', $body_content );
$headers = 'Reply-To: ' . $email;
/*
By default, this form will send from wordpress@yourdomain.com 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;
}
}
if ( $page_layout === 'right' ) { ?>
<div class="primary-sidebar">
<?php dynamic_sidebar( 'internal-sidebar' ); ?>
</div><!-- END .primary-sidebar -->
<?php } ?>
<article id="post-<?php the_ID(); ?>" class="primary-content
<?php
echo esc_html( $page_layout );
if ( $page_layout != 'right' ) {
echo ' no-sidebar'; }
?>
">
<?php if ( ( function_exists( 'has_post_thumbnail' ) ) && ( has_post_thumbnail() ) ) { ?>
<div class="entry-media">
<?php the_post_thumbnail( 'post-feat' ); ?>
</div><!-- END .entry-media -->
<?php } //END if ( (function_exists('has_post_thumbnail')) ?>
<div class="entry-content">
<div class="contact-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
wp_link_pages(
array(
'before' => '<div class="page-link"><span>' . __( 'Pages:', 'bricks' ) . '</span>',
'after' => '</div>',
)
);
?>
<?php
if ( $page_layout === 'full' ) {
dynamic_sidebar( 'Contact Sidebar' ); }
?>
</div><!-- END .contact-content -->
<?php if ( get_theme_mod( 'bean_contact_form' ) == true ) { // IF CONTACT FORM IS TRUE VIA CUSTOMIZER ?>
<?php $required = '<span class="required">*</span>'; ?>
<form action="<?php the_permalink(); ?>" id="BeanForm" method="post">
<?php if ( isset( $emailSent ) && $emailSent == true ) { ?>
<div class="contact-alert success">
<?php echo apply_filters( 'bean_contactform_success_msg', esc_html__( 'Your message was sent. Thanks.', 'bricks' ) ); ?>
</div><!-- END .alert alert-success -->
<?php } // END SUCCESS ALERT ?>
<?php if ( isset( $hasError ) || isset( $captchaError ) ) { ?>
<div class="contact-alert fail">
<?php echo apply_filters( 'bean_contactform_error_msg', esc_html__( 'An error occured. Try again.', 'bricks' ) ); ?>
</div><!-- END .alert alert-success -->
<?php } // END FAIL ALERT ?>
<ul class="bean-contactform">
<li class="name">
<label for="contactName">
<?php
_e( 'Name', 'bricks' );
echo esc_html( $required;
?>
</label>
<input type="text" name="contactName" id="contactName" value="
<?php
if ( isset( $_POST['contactName'] ) ) {
echo $_POST['contactName'];}
?>
" class="required requiredField" />
</li>
<?php do_action( 'bean_after_contactform_namefield' ); ?>
<li class="email">
<label for="email">
<?php
_e( 'Email', 'bricks' );
echo $required;
?>
</label>
<input type="text" name="email" id="email" value="
<?php
if ( isset( $_POST['email'] ) ) {
echo $_POST['email'];}
?>
" class="required requiredField email" />
</li>
<?php do_action( 'bean_after_contactform_emailfield' ); ?>
<li class="textarea"><label for="commentsText">
<?php
_e( 'Message', 'bricks' );
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>
<?php do_action( 'bean_after_contactform_allfields' ); ?>
<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', 'Send Message', 'bricks' ); ?></button>
</li>
<?php do_action( 'bean_after_contactform_submit' ); ?>
</ul>
</form><!-- END #BeanForm -->
<?php } // END if( get_theme_mod( 'bean_contact_form' ) == true ) ?>
</div><!-- END .entry-content -->
</article>
<?php
get_footer();