-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
120 lines (102 loc) · 3.77 KB
/
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
<?php
/*
Template Name: Contact Us
*/
get_header();
$contact_page_data = get_option('ashad_contactpage_data',array(
'sitekey' => '',
'secretkey' => ''
));
?>
<script>
function onLoadCallback() {
grecaptcha.render('divRecaptcha', {
sitekey: '<?php echo $contact_page_data['sitekey'] ?>',
callback: token => {
document.getElementById('recaptchaToken').value = token
}
})
}
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=onLoadCallback&render=explicit" async defer></script>
<style type="text/css" media="screen">
.container {
margin: 0px auto;
max-width: 600px;
}
</style>
<section class="content">
<div class="post">
<article class="post-content fullwidth">
<div class="container">
<h2>Talk to me</h2>
<div id="form" class="contact-form">
<form accept-charset="UTF-8" action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="POST" v-on:submit.prevent="validateBeforeSubmit" ref="contact">
<fieldset>
<input type="text" name="name" placeholder="Your name" v-validate="'required'"
:class="{ 'has-error': errors.has('name') }">
<span v-if="errors.has('name')" v-cloak>${ errors.first('name') }</span>
<input type="text" name="email" placeholder="Your email" v-validate="'required|email'"
:class="{ 'has-error': errors.has('email') }">
<span v-if="errors.has('email')" v-cloak>${ errors.first('email') }</span>
<input type="text" name="subject" placeholder="Subject" v-validate="'required'"
:class="{ 'has-error': errors.has('subject') }">
<span v-if="errors.has('subject')" v-cloak>${ errors.first('subject') }</span>
<textarea name="message" onkeyup="adjust_textarea(this)" placeholder="Your message" v-validate="'required'"
:class="{ 'has-error': errors.has('message') }"></textarea>
<span v-if="errors.has('message')" v-cloak>${ errors.first('message') }</span>
<input type="hidden" name="action" value="ashad_contact_form">
<input type="hidden" id="recaptchaToken" name="recaptchaToken" value="">
<?php wp_nonce_field('ashad_contact_form'); ?>
<div id="divRecaptcha" class="g-recaptcha"></div>
<button type="submit">Send</button>
</fieldset>
</form>
</div>
</div>
</article>
</div>
</section>
<script type="text/javascript">
function adjust_textarea(h) {
h.style.height = "200px";
h.style.height = (h.scrollHeight)+"px";
}
</script>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script type="text/javascript">
Vue.use(VeeValidate);
const dictionary = {
custom: {
name: {
required: "Name is required"
},
email: {
required: "Email is required",
email: "Email is invalid"
},
subject: {
required: "Message subject is required"
},
message: {
required: "Message is required"
}
}
};
VeeValidate.Validator.updateDictionary(dictionary);
VeeValidate.Validator.setLocale("en");
new Vue({
el: '#form',
delimiters: ['${', '}'],
methods: {
validateBeforeSubmit: function () {
this.$validator.validateAll();
if (!this.errors.any()) {
this.$refs.contact.submit();
}
}
}
});
</script>
<?php get_footer(); ?>