# html-forms/1.0.1/src/Form.php

HTML Forms – Simple WordPress Forms Plugin, version 1.0.1. 86 lines.

- Page: https://pluginprobe.com/plugins/html-forms/1.0.1/code/src/Form.php
- Raw: https://pluginprobe.com/plugins/html-forms/1.0.1/raw/src/Form.php
- Modified: 2017-10-28T18:50:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/html-forms/1.0.1/code/src/Form.php#L10-L20`.

```php
<?php

namespace HTML_Forms;

class Form {

    public $ID = 0;
    public $title = '';
    public $slug = '';
    public $markup = '';
    public $messages = array();
    public $settings = array();

    /**
     * Form constructor.
     *
     * @param $ID
     */
    public function __construct( $ID ) {
        $this->ID = $ID;
    }

    /**
     * @return string
     */
    public function __toString() {
        $form = $this;

        /**
         * Filters the CSS classes to be added to this form's class attribute.
         *
         * @param array $form_classes
         * @param Form $form
         */
        $form_classes_attr = apply_filters( 'hf_form_element_class_attr', '', $form );

        /**
         * Filters the action attribute for this form.
         *
         * @param string $form_action
         * @param Form $form
         */
        $form_action = apply_filters( 'hf_form_element_action_attr', null, $form );
        $form_action_attr = is_null( $form_action ) ? '' : sprintf('action="%s"', $form_action );

        $html = '';
        $html .= sprintf( '<!-- HTML Forms v%s - %s -->', HTML_FORMS_VERSION, 'https://wordpress.org/plugins/html-forms/' );
        $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 ) );

        $html .= '<div class="hf-fields-wrap">';
        $html .= sprintf( '<input type="hidden" name="_hf_form_id" value="%d" />', $this->ID );
        $html .= sprintf( '<div style="display: none;"><input type="text" name="_hf_h%d" value="" /></div>', $this->ID );
        $html .= $this->markup;
        $html .= '<noscript>' . __( "Please enable JavaScript for this form to work.", 'html-forms' ) . '</noscript>';
        $html .= '</div>';
        $html .= '</form>';
        $html .= '<!-- / HTML Forms -->';

        /**
         * Filters the resulting HTML for this form.
         *
         * @param string $html
         * @param Form $form
         */
        $html = apply_filters( 'hf_form_html', $html, $form );
        return $html;
    }

    /**
     * @return array
     */
    public function get_required_fields() {
        $required_fields = explode( ',', $this->settings['required_fields'] );
        return $required_fields;
    }

    /**
     * @return array
     */
    public function get_email_fields() {
        $email_fields = explode( ',', $this->settings['email_fields'] );
        return $email_fields;
    }

}

```
