PluginProbe
HTML Forms – Simple WordPress Forms Plugin / 1.0
HTML Forms – Simple WordPress Forms Plugin v1.0
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, at src/Form.php

85 lines 2.4 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 $this->ID = $ID;
21 }
22
23 /**
24 * @return string
25 */
26 public function __toString() {
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">', $form_action_attr, $this->ID, $form_classes_attr );
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 array
71 */
72 public function get_required_fields() {
73 $required_fields = explode( ',', $this->settings['required_fields'] );
74 return $required_fields;
75 }
76
77 /**
78 * @return array
79 */
80 public function get_email_fields() {
81 $email_fields = explode( ',', $this->settings['email_fields'] );
82 return $email_fields;
83 }
84
85 }