PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.0.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.0.3
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / class-frontend-form.php

class-frontend-form.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.0.3, at includes/class-frontend-form.php

157 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The frontend form class
5 */
6 class WeForms_Frontend extends WPUF_Render_Form {
7
8 public function __construct() {
9 add_shortcode( 'weforms', array( $this, 'render_shortcode' ) );
10 }
11
12 /**
13 * Render contact form shortcode
14 *
15 * @param array $atts
16 * @param string $contents
17 *
18 * @return string
19 */
20 public function render_shortcode( $atts, $contents = '' ) {
21 extract( shortcode_atts( array( 'id' => 0 ), $atts ) );
22 ob_start();
23
24 $is_open = wpuf_is_form_submission_open( $id );
25
26 if ( is_wp_error( $is_open ) ) {
27 return '<div class="wpuf-info">' . $is_open->get_error_message() . '</div>';
28 }
29
30 $form_settings = wpuf_get_form_settings( $id );
31
32 // var_dump( $form_settings );
33 $this->render_form( $id );
34
35 return ob_get_clean();
36 }
37
38 /**
39 * Handles the add post shortcode
40 *
41 * @param $atts
42 */
43 function render_form( $form_id, $post_id = NULL, $preview = false ) {
44 $form_status = get_post_status( $form_id );
45
46 if ( ! $form_status ) {
47 echo '<div class="wpuf-message">' . __( 'Your selected form is no longer available.', 'weforms' ) . '</div>';
48 return;
49 }
50
51 if ( $form_status != 'publish' ) {
52 echo '<div class="wpuf-message">' . __( "Please make sure you've published your form.", 'weforms' ) . '</div>';
53 return;
54 }
55
56 $form_vars = wpuf_get_form_fields( $form_id );
57 $form_settings = wpuf_get_form_settings( $form_id );
58 $show_credit = weforms_get_settings( 'credit', false );
59 ?>
60
61 <form class="wpuf-form-add" action="" method="post">
62
63 <ul class="wpuf-form form-label-<?php echo $form_settings['label_position']; ?>">
64 <?php
65 $this->render_items( $form_vars, $post_id, 'contact_form', $form_id, $form_settings );
66 $this->submit_button( $form_id, $form_settings, $post_id );
67 ?>
68 </ul>
69
70 </form>
71
72 <?php
73 if ( $show_credit ) {
74 printf( '<em>' . __( 'Powered by <a href="%s" target="_blank">weForms</a>', 'weforms' ) . '</em>', 'https://wordpress.org/plugins/weforms/' );
75 }
76
77 weforms_track_form_view( $form_id );
78 }
79
80 function submit_button( $form_id, $form_settings, $post_id ) {
81 ?>
82 <li class="wpuf-submit">
83 <div class="wpuf-label">
84 &nbsp;
85 </div>
86
87 <?php wp_nonce_field( 'wpuf_form_add' ); ?>
88
89 <input type="hidden" name="form_id" value="<?php echo $form_id; ?>">
90 <input type="hidden" name="page_id" value="<?php echo get_post() ? get_the_ID() : '0'; ?>">
91 <input type="hidden" name="action" value="wpuf_submit_contact">
92
93 <input type="submit" name="submit" value="<?php echo $form_settings['submit_text']; ?>" />
94 </li>
95 <?php
96 }
97
98 function field_name( $form_field, $post_id, $type, $form_id ) {
99 // var_dump( $form_field );
100 ?>
101 <div class="wpuf-fields">
102 <div class="wpuf-name-field-wrap format-<?php echo $form_field['format']; ?>">
103 <div class="wpuf-name-field-first-name">
104 <input
105 name="<?php echo $form_field['name'] ?>[first]"
106 type="text"
107 placeholder="<?php echo esc_attr( $form_field['first_name']['placeholder'] ); ?>"
108 value="<?php echo esc_attr( $form_field['first_name']['default'] ); ?>"
109 size="40"
110 data-required="<?php echo $form_field['required'] ?>"
111 data-type="text"
112 class="textfield wpuf_<?php echo $form_field['name']; ?>_<?php echo $form_id; ?>"
113 >
114
115 <?php if ( ! $form_field['hide_subs'] ) : ?>
116 <label class="wpuf-form-sub-label"><?php _e( 'First', 'weforms' ); ?></label>
117 <?php endif; ?>
118 </div>
119
120 <?php if ( $form_field['format'] != 'first-last' ) : ?>
121 <div class="wpuf-name-field-middle-name">
122 <input
123 name="<?php echo $form_field['name'] ?>[middle]"
124 type="text" class="textfield"
125 placeholder="<?php echo esc_attr( $form_field['middle_name']['placeholder'] ); ?>"
126 value="<?php echo esc_attr( $form_field['middle_name']['default'] ); ?>"
127 size="40"
128 >
129
130 <?php if ( ! $form_field['hide_subs'] ) : ?>
131 <label class="wpuf-form-sub-label"><?php _e( 'Middle', 'weforms' ); ?></label>
132 <?php endif; ?>
133 </div>
134 <?php else: ?>
135 <input type="hidden" name="<?php echo $form_field['name'] ?>[middle]" value="">
136 <?php endif; ?>
137
138 <div class="wpuf-name-field-last-name">
139 <input
140 name="<?php echo $form_field['name'] ?>[last]"
141 type="text" class="textfield"
142 placeholder="<?php echo esc_attr( $form_field['last_name']['placeholder'] ); ?>"
143 value="<?php echo esc_attr( $form_field['last_name']['default'] ); ?>"
144 size="40"
145 >
146 <?php if ( ! $form_field['hide_subs'] ) : ?>
147 <label class="wpuf-form-sub-label"><?php _e( 'Last', 'weforms' ); ?></label>
148 <?php endif; ?>
149 </div>
150 </div>
151 </div>
152 <?php
153
154 $this->conditional_logic( $form_field, $form_id );
155 }
156 }
157