-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-contact.php
275 lines (219 loc) · 12 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
/**
* Template Name: Contact Form
*
* The contact form page template displays the a
* simple contact form in your website's content area.
*
* @package WooFramework
* @subpackage Template
*/
global $woo_options;
get_header();
$nameError = '';
$emailError = '';
$commentError = '';
$mathCheck = '';
//If the form is submitted
if( isset( $_POST['submitted'] ) ) {
//Check to see if the honeypot captcha field was filled in
if( trim( $_POST['checking'] ) !== '' ) {
$captchaError = true;
} else {
// Check math field
if( $_POST['mathCheck'] != 9 && strcasecmp( $_POST['mathCheck'], 'nine' ) != 0 ) {
$mathCheck = __( 'You got the maths wrong.', 'woothemes' );
$hasError = true;
} else {
$math = trim( $_POST['mathCheck'] );
}
//Check to make sure that the name field is not empty
if( trim( $_POST['contactName'] ) === '' ) {
$nameError = __( 'You forgot to enter your name.', 'woothemes' );
$hasError = true;
} else {
$name = strip_tags( trim( $_POST['contactName'] ) );
}
//Check to make sure sure that a valid email address is submitted
if( trim( $_POST['email'] ) === '' ) {
$emailError = __( 'You forgot to enter your email address.', 'woothemes' );
$hasError = true;
} else if ( ! is_email( sanitize_email( $_POST['email'] ) ) ) {
$emailError = __( 'You entered an invalid email address.', 'woothemes' );
$hasError = true;
} else {
$email = sanitize_email( trim( $_POST['email'] ) );
}
//Check to make sure comments were entered
if( trim( $_POST['comments'] ) === '' ) {
$commentError = __( 'You forgot to enter your comments.', 'woothemes' );
$hasError = true;
} else {
$comments = sanitize_text_field( stripslashes( trim( $_POST['comments'] ) ) );
}
//If there is no error, send the email
if ( ! isset( $hasError ) ) {
$emailTo = get_option( 'woo_contactform_email' );
$subject = __( 'Contact Form Submission from ', 'woothemes' ).$name;
$sendCopy = false;
if ( isset( $_POST['sendCopy'] ) && $_POST['sendCopy'] !== '' ) {
$sendCopy = true;
}
$body = sprintf( __( "Name: %s \n\nEmail: %s \n\nComments: %s", 'woothemes' ), $name, $email, $comments );
$headers = __( 'From: ', 'woothemes') . "$name <$email>" . "\r\n" . __( 'Reply-To: ', 'woothemes' ) . $email;
wp_mail( $emailTo, $subject, $body, $headers );
if ( $sendCopy == true ) {
$nameTo = get_option( 'woo_contact_title' );
if ( '' == trim( $nameTo ) ) {
$nameTo = get_bloginfo( 'name' );
}
$nameTo = strip_tags( trim( $nameTo ) );
$subject = __( 'You emailed ', 'woothemes' ) . get_bloginfo( 'title' );
$headers = __( 'From: ', 'woothemes' ) . "$nameTo <$emailTo>";
wp_mail( $email, $subject, $body, $headers );
}
$emailSent = true;
}
}
}
?>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
jQuery(document).ready(function() {
jQuery( 'form#contactForm').submit(function() {
jQuery( 'form#contactForm .error').remove();
var hasError = false;
jQuery( '.requiredField').each(function() {
if(jQuery(this).hasClass('math')) {
if( jQuery.trim(jQuery(this).val()) != 9 && jQuery.trim(jQuery(this).val()).toLowerCase() != 'nine' ) {
jQuery(this).parent().append( '<span class="error"><?php _e( 'You got the maths wrong', 'woothemes' ); ?>.</span>' );
jQuery(this).addClass( 'inputError' );
hasError = true;
}
} else {
if(jQuery.trim(jQuery(this).val()) == '') {
var labelText = jQuery(this).prev( 'label').text();
jQuery(this).parent().append( '<span class="error"><?php _e( 'You forgot to enter your', 'woothemes' ); ?> '+labelText+'.</span>' );
jQuery(this).addClass( 'inputError' );
hasError = true;
} else if(jQuery(this).hasClass( 'email')) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
var labelText = jQuery(this).prev( 'label').text();
jQuery(this).parent().append( '<span class="error"><?php _e( 'You entered an invalid', 'woothemes' ); ?> '+labelText+'.</span>' );
jQuery(this).addClass( 'inputError' );
hasError = true;
}
}
}
});
if(!hasError) {
var formInput = jQuery(this).serialize();
jQuery.post(jQuery(this).attr( 'action'),formInput, function(data){
jQuery( 'form#contactForm').slideUp( "fast", function() {
jQuery(this).before( '<?php echo do_shortcode( '[box type="tick"]' . __( '<strong>Thanks!</strong> Your email was successfully sent.', 'woothemes' ) . '[/box]' ); ?>' );
});
});
}
return false;
});
});
//-->!]]>
</script>
<?php woo_content_before(); ?>
<div id="content" class="col-full">
<?php
// Output Google Map
if ( isset( $woo_options['woo_contactform_map_coords'] ) && '' != $woo_options['woo_contactform_map_coords'] ) {
woo_maps_contact_output( "geocoords=" . $woo_options['woo_contactform_map_coords'] );
echo do_shortcode( '[divider]' );
}
?>
<div id="main-sidebar-container">
<!-- #main Starts -->
<?php woo_main_before(); ?>
<section id="main">
<?php woo_loop_before(); ?>
<!-- Post Starts -->
<?php woo_post_before(); ?>
<div id="contact-page" class="page">
<?php woo_post_inside_before(); ?>
<h1 class="title"><?php the_title(); ?></h1>
<?php if( isset( $emailSent ) && $emailSent == true ) { ?>
<p class="info"><?php _e( 'Your email was successfully sent.', 'woothemes' ); ?></p>
<?php } else { ?>
<?php if ( have_posts() ) { ?>
<?php while ( have_posts() ) { the_post(); ?>
<section class="entry">
<?php the_content(); ?>
<div class="location-twitter">
<?php if ( isset( $woo_options['woo_contact_panel'] ) && $woo_options['woo_contact_panel'] == 'true' ) { ?>
<section id="office-location"<?php if ( ( isset($woo_options['woo_contact_subscribe_and_connect']) && $woo_options['woo_contact_subscribe_and_connect'] == 'true' ) ) { ?> class="col-left"<?php } ?>>
<?php if (isset($woo_options['woo_contact_title'])) { ?><h3><?php echo stripslashes( $woo_options['woo_contact_title'] ); ?></h3><?php } ?>
<ul>
<?php if (isset($woo_options['woo_contact_title']) && $woo_options['woo_contact_title'] != '' ) { ?><li><?php echo stripslashes( $woo_options['woo_contact_address'] ); ?></li><?php } ?>
<?php if (isset($woo_options['woo_contact_number']) && $woo_options['woo_contact_number'] != '' ) { ?><li><?php _e('Tel:','woothemes'); ?> <?php echo $woo_options['woo_contact_number']; ?></li><?php } ?>
<?php if (isset($woo_options['woo_contact_fax']) && $woo_options['woo_contact_fax'] != '' ) { ?><li><?php _e('Fax:','woothemes'); ?> <?php echo $woo_options['woo_contact_fax']; ?></li><?php } ?>
</ul>
</section>
<?php } ?>
<div class="contact-social<?php if ( ( isset( $woo_options['woo_contact_panel'] ) && $woo_options['woo_contact_panel'] == 'true' ) || ( isset($woo_options['woo_contact_subscribe_and_connect']) && $woo_options['woo_contact_subscribe_and_connect'] == 'true' ) ) { ?> col-right<?php } ?>">
<?php if ( isset($woo_options['woo_contact_subscribe_and_connect']) && $woo_options['woo_contact_subscribe_and_connect'] == 'true' ) { woo_subscribe_connect( 'true' ); } ?>
</div>
<div class="clear"></div>
</div><!-- /.location-twitter -->
</section>
<?php if( isset( $hasError ) || isset( $captchaError ) ) { ?>
<p class="alert"><?php _e( 'There was an error submitting the form.', 'woothemes' ); ?></p>
<?php } ?>
<?php if ( get_option( 'woo_contactform_email' ) == '' ) { ?>
<?php echo do_shortcode( '[box type="alert"]' . __( 'Please <strong>add your e-mail</strong> in <em>Contact Page > Contact Form E-mail</em>.', 'woothemes' ) . '[/box]' ); ?>
<?php } ?>
<form action="<?php the_permalink(); ?>" id="contactForm" method="post">
<ol class="forms">
<li><label for="contactName"><?php _e( 'Name', 'woothemes' ); ?></label>
<input type="text" name="contactName" id="contactName" value="<?php if( isset( $_POST['contactName'] ) ) { echo esc_attr( $_POST['contactName'] ); } ?>" class="txt requiredField" />
<?php if($nameError != '') { ?>
<span class="error"><?php echo $nameError;?></span>
<?php } ?>
</li>
<li><label for="email"><?php _e( 'Email', 'woothemes' ); ?></label>
<input type="text" name="email" id="email" value="<?php if( isset( $_POST['email'] ) ) { echo esc_attr( $_POST['email'] ); } ?>" class="txt requiredField email" />
<?php if($emailError != '') { ?>
<span class="error"><?php echo $emailError;?></span>
<?php } ?>
</li>
<li class="textarea"><label for="commentsText"><?php _e( 'Message', 'woothemes' ); ?></label>
<textarea name="comments" id="commentsText" rows="20" cols="30" class="requiredField"><?php if( isset( $_POST['comments'] ) ) { echo esc_textarea( $_POST['comments'] ); } ?></textarea>
<?php if( $commentError != '' ) { ?>
<span class="error"><?php echo $commentError; ?></span>
<?php } ?>
</li>
<li><label for="mathCheck"><?php _e( 'Solve:', 'woothemes' ); ?> 3 + 6</label>
<input type="text" name="mathCheck" id="mathCheck" value="<?php if( isset( $_POST['mathCheck'] ) ) { echo esc_attr( $_POST['mathCheck'] ); } ?>" class="txt requiredField math" />
<?php if($mathCheck != '') { ?>
<span class="error"><?php echo $mathCheck;?></span>
<?php } ?>
</li>
<li class="inline"><input type="checkbox" name="sendCopy" id="sendCopy" value="true"<?php if( isset( $_POST['sendCopy'] ) && $_POST['sendCopy'] == true ) { echo ' checked="checked"'; } ?> /><label for="sendCopy"><?php _e( 'Send a copy of this email to yourself', 'woothemes' ); ?></label></li>
<li class="screenReader"><label for="checking" class="screenReader"><?php _e( 'If you want to submit this form, do not enter anything in this field', 'woothemes' ); ?></label><input type="text" name="checking" id="checking" class="screenReader" value="<?php if( isset( $_POST['checking'] ) ) { echo esc_attr( $_POST['checking'] ); } ?>" /></li>
<li class="buttons"><input type="hidden" name="submitted" id="submitted" value="true" /><input class="submit button" type="submit" value="<?php esc_attr_e( 'Submit', 'woothemes' ); ?>" /></li>
</ol>
</form>
<?php
} // End WHILE Loop
}
}
?>
<div class="fix"></div>
<?php woo_post_inside_after(); ?>
</div><!-- /#contact-page -->
<?php woo_post_after(); ?>
</section><!-- /#main -->
<?php woo_main_after(); ?>
<?php get_sidebar(); ?>
</div><!-- /#main-sidebar-container -->
<?php get_sidebar( 'alt' ); ?>
</div><!-- /#content -->
<?php woo_content_after(); ?>
<?php get_footer(); ?>