PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.5.6.1
JetFormBuilder — Dynamic Blocks Form Builder v3.5.6.1
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / form-messages / builder.php
builder.php
104 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Jet_Form_Builder\Form_Messages;
5
6 // If this file is called directly, abort.
7 use Jet_Form_Builder\Classes\Get_Template_Trait;
8 use JFB_Modules\Rich_Content;
9
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 /**
15 * Form messages class
16 */
17 class Builder {
18
19 use Get_Template_Trait;
20
21 private $status;
22
23 /**
24 * Set form submittion status
25 *
26 * @param [type] $status [description]
27 *
28 * @return Builder
29 */
30 public function set_form_status( $status ) {
31 $this->status = $status;
32
33 return $this;
34 }
35
36 public function get_manager( $data = array() ) {
37 return jet_form_builder()->msg_router->get_manager( $data );
38 }
39
40 /**
41 * Get form submitting status
42 */
43 public function get_form_status() {
44 if ( ! $this->status ) {
45 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
46 $this->status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : null;
47 }
48
49 return $this->status;
50 }
51
52 public function render_empty_field_message() {
53 $message_content = $this->get_manager()->get_message( 'empty_field' );
54
55 include $this->get_global_template( 'common/field-message.php' );
56 }
57
58 /**
59 * Render form messages
60 *
61 * @return void
62 */
63 public function render_messages() {
64 $status = $this->get_form_status();
65
66 if ( ! $status ) {
67 return;
68 }
69
70 $info = new Status_Info( $status );
71 $message_content = Rich_Content\Module::rich( $this->get_manager()->get_message_by_info( $info ) );
72
73 $class = 'jet-form-builder-message';
74 $class .= ' jet-form-builder-message--' . $info->get_css_class();
75
76 include $this->get_global_template( 'common/messages.php' );
77 }
78
79 /**
80 * Render message samples for editor
81 */
82 public function render_messages_samples() {
83 // Render success sample
84 $this->set_form_status( 'success' );
85 $this->render_messages();
86
87 // Render error sample
88 $this->set_form_status( 'failed' );
89 $this->render_messages();
90
91 // Reset status
92 $this->set_form_status( null );
93 }
94
95 public function get_rendered_messages() {
96 ob_start();
97 $this->render_messages();
98
99 return ob_get_clean();
100 }
101
102
103 }
104