| 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 |
} |