PluginProbe
HTML Forms – Simple WordPress Forms Plugin / 1.0.2
HTML Forms – Simple WordPress Forms Plugin v1.0.2
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 All 66 releases
html-forms / src / Form.php

Form.php in HTML Forms – Simple WordPress Forms Plugin 1.0.2, at src/Form.php

104 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace HTML_Forms;
4
5 class Form {
6
7 public $ID = 0;
8 public $title = '';
9 public $slug = '';
10 public $markup = '';
11 public $messages = array();
12 public $settings = array();
13
14 /**
15 * Form constructor.
16 *
17 * @param $ID
18 */
19 public function __construct( $ID )
20 {
21 $this->ID = $ID;
22 }
23
24 public function get_html()
25 {
26 $form = $this;
27 $form = $this;
28
29 /**
30 * Filters the CSS classes to be added to this form's class attribute.
31 *
32 * @param array $form_classes
33 * @param Form $form
34 */
35 $form_classes_attr = apply_filters( 'hf_form_element_class_attr', '', $form );
36
37 /**
38 * Filters the action attribute for this form.
39 *
40 * @param string $form_action
41 * @param Form $form
42 */
43 $form_action = apply_filters( 'hf_form_element_action_attr', null, $form );
44 $form_action_attr = is_null( $form_action ) ? '' : sprintf('action="%s"', $form_action );
45
46 $html = '';
47 $html .= sprintf( '<!-- HTML Forms v%s - %s -->', HTML_FORMS_VERSION, 'https://wordpress.org/plugins/html-forms/' );
48 $html .= sprintf( '<form method="post" %s class="hf-form hf-form-%d %s" data-title="%s" data-slug="%s">', $form_action_attr, $this->ID, esc_attr( $form_classes_attr ), esc_attr( $this->title ), esc_attr( $this->slug ) );
49
50 $html .= '<div class="hf-fields-wrap">';
51 $html .= sprintf( '<input type="hidden" name="_hf_form_id" value="%d" />', $this->ID );
52 $html .= sprintf( '<div style="display: none;"><input type="text" name="_hf_h%d" value="" /></div>', $this->ID );
53 $html .= $this->markup;
54 $html .= '<noscript>' . __( "Please enable JavaScript for this form to work.", 'html-forms' ) . '</noscript>';
55 $html .= '</div>';
56 $html .= '</form>';
57 $html .= '<!-- / HTML Forms -->';
58
59 /**
60 * Filters the resulting HTML for this form.
61 *
62 * @param string $html
63 * @param Form $form
64 */
65 $html = apply_filters( 'hf_form_html', $html, $form );
66 return $html;
67 }
68
69 /**
70 * @return string
71 */
72 public function __toString()
73 {
74 return $this->get_html();
75 }
76
77 /**
78 * @return array
79 */
80 public function get_required_fields()
81 {
82 if( empty( $this->settings['required_fields'] ) ) {
83 return array();
84 }
85
86 $required_fields = explode( ',', $this->settings['required_fields'] );
87 return $required_fields;
88 }
89
90 /**
91 * @return array
92 */
93 public function get_email_fields()
94 {
95 if( empty( $this->settings['email_fields'] ) ) {
96 return array();
97 }
98
99 $email_fields = explode( ',', $this->settings['email_fields'] );
100 return $email_fields;
101 }
102
103 }
104