| 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 |
?> |
| 59 |
|
| 60 |
<form class="wpuf-form-add" action="" method="post"> |
| 61 |
|
| 62 |
<ul class="wpuf-form form-label-<?php echo $form_settings['label_position']; ?>"> |
| 63 |
<?php |
| 64 |
$this->render_items( $form_vars, $post_id, 'contact_form', $form_id, $form_settings ); |
| 65 |
$this->submit_button( $form_id, $form_settings, $post_id ); |
| 66 |
?> |
| 67 |
</ul> |
| 68 |
|
| 69 |
</form> |
| 70 |
|
| 71 |
<?php |
| 72 |
weforms_track_form_view( $form_id ); |
| 73 |
} |
| 74 |
|
| 75 |
function submit_button( $form_id, $form_settings, $post_id ) { |
| 76 |
?> |
| 77 |
<li class="wpuf-submit"> |
| 78 |
<div class="wpuf-label"> |
| 79 |
|
| 80 |
</div> |
| 81 |
|
| 82 |
<?php wp_nonce_field( 'wpuf_form_add' ); ?> |
| 83 |
|
| 84 |
<input type="hidden" name="form_id" value="<?php echo $form_id; ?>"> |
| 85 |
<input type="hidden" name="page_id" value="<?php echo get_post() ? get_the_ID() : '0'; ?>"> |
| 86 |
<input type="hidden" name="action" value="wpuf_submit_contact"> |
| 87 |
|
| 88 |
<input type="submit" name="submit" value="<?php echo $form_settings['submit_text']; ?>" /> |
| 89 |
</li> |
| 90 |
<?php |
| 91 |
} |
| 92 |
|
| 93 |
function field_name( $form_field, $post_id, $type, $form_id ) { |
| 94 |
// var_dump( $form_field ); |
| 95 |
?> |
| 96 |
<div class="wpuf-fields"> |
| 97 |
<div class="wpuf-name-field-wrap format-<?php echo $form_field['format']; ?>"> |
| 98 |
<div class="wpuf-name-field-first-name"> |
| 99 |
<input |
| 100 |
name="<?php echo $form_field['name'] ?>[first]" |
| 101 |
type="text" |
| 102 |
placeholder="<?php echo esc_attr( $form_field['first_name']['placeholder'] ); ?>" |
| 103 |
value="<?php echo esc_attr( $form_field['first_name']['default'] ); ?>" |
| 104 |
size="40" |
| 105 |
data-required="<?php echo $form_field['required'] ?>" |
| 106 |
data-type="text" |
| 107 |
class="textfield wpuf_<?php echo $form_field['name']; ?>_<?php echo $form_id; ?>" |
| 108 |
> |
| 109 |
|
| 110 |
<?php if ( ! $form_field['hide_subs'] ) : ?> |
| 111 |
<label class="wpuf-form-sub-label"><?php _e( 'First', 'weforms' ); ?></label> |
| 112 |
<?php endif; ?> |
| 113 |
</div> |
| 114 |
|
| 115 |
<?php if ( $form_field['format'] != 'first-last' ) : ?> |
| 116 |
<div class="wpuf-name-field-middle-name"> |
| 117 |
<input |
| 118 |
name="<?php echo $form_field['name'] ?>[middle]" |
| 119 |
type="text" class="textfield" |
| 120 |
placeholder="<?php echo esc_attr( $form_field['middle_name']['placeholder'] ); ?>" |
| 121 |
value="<?php echo esc_attr( $form_field['middle_name']['default'] ); ?>" |
| 122 |
size="40" |
| 123 |
> |
| 124 |
|
| 125 |
<?php if ( ! $form_field['hide_subs'] ) : ?> |
| 126 |
<label class="wpuf-form-sub-label"><?php _e( 'Middle', 'weforms' ); ?></label> |
| 127 |
<?php endif; ?> |
| 128 |
</div> |
| 129 |
<?php else: ?> |
| 130 |
<input type="hidden" name="<?php echo $form_field['name'] ?>[middle]" value=""> |
| 131 |
<?php endif; ?> |
| 132 |
|
| 133 |
<div class="wpuf-name-field-last-name"> |
| 134 |
<input |
| 135 |
name="<?php echo $form_field['name'] ?>[last]" |
| 136 |
type="text" class="textfield" |
| 137 |
placeholder="<?php echo esc_attr( $form_field['last_name']['placeholder'] ); ?>" |
| 138 |
value="<?php echo esc_attr( $form_field['last_name']['default'] ); ?>" |
| 139 |
size="40" |
| 140 |
> |
| 141 |
<?php if ( ! $form_field['hide_subs'] ) : ?> |
| 142 |
<label class="wpuf-form-sub-label"><?php _e( 'Last', 'weforms' ); ?></label> |
| 143 |
<?php endif; ?> |
| 144 |
</div> |
| 145 |
</div> |
| 146 |
</div> |
| 147 |
<?php |
| 148 |
|
| 149 |
$this->conditional_logic( $form_field, $form_id ); |
| 150 |
} |
| 151 |
} |
| 152 |
|