/
acf-form-template.php
85 lines (66 loc) · 2.24 KB
/
acf-form-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
<?php
/**
* Re-usable contact form
*
* @version 0.2
* + added actions hooks
*/
?>
<form id="alpha-form-<?php echo $template->id; ?>" action="<?php echo $template->form_url; ?>" method="post" class="alpha-contact-form">
<p>
<label>
<span>Name</span>
<input type="text" name="name" class="alpha-field-name acf-field" />
</label>
</p>
<p>
<label class="required-field">
<span>E-Mail</span>
<input type="text" name="from" class="alpha-field-from acf-field required" />
</label>
</p>
<?php
// hook before output of custom form fields
do_action('acf_widget_form_before_custom_fields');
if(isset($template->custom_fields) != false) {
foreach($template->custom_fields as $strCustomField) { ?>
<p>
<label>
<span><?php echo str_replace('_', ' ', $strCustomField); ?></span>
<input type="text" name="<?php echo $strCustomField; ?>" class="alpha-custom-field acf-field <?php echo $strCustomField; ?>" />
</label>
</p>
<?php }
}
// hook after output of custom form fields
do_action('acf_widget_form_after_custom_fields');
?>
<p>
<label class="required-field">
<span>Message</span>
<textarea name="message" cols="40" rows="5" class="alpha-field-message acf-field required"></textarea>
</label>
</p>
<?php // hook after the message field - eg. to insert a CAPTCHA section
do_action('acf_widget_form_after_message_field'); ?>
<?php // hook for hidden fields
do_action('acf_worm_form_before_hidden_fields'); ?>
<input type="hidden" name="id" class="alpha-form-widget-id" id="<?php echo $this->id; ?>" value="<?php echo $this->id; ?>" />
<?php // hook for hidden fields
do_action('acf_worm_form_after_hidden_fields'); ?>
<?php // hook before form controls
do_action('acf_worm_form_before_form_controls'); ?>
<p class="form-controls"><button type="submit" class="alpha-button-submit">Submit</button></p>
<?php // hook AFTER form controls
do_action('acf_worm_form_after_form_controls'); ?>
</form>
<style type="text/css">
#alpha-form-<?php echo $template->id; ?> .required-field label span {
font-weight: bold;
}
#alpha-form-<?php echo $template->id; ?> .required.missing {
border: 2xp solid #c33;
background-color: #fdd;
color: #111;
}
</style>