| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Text Field Class |
| 5 |
*/ |
| 6 |
class WeForms_Form_Field_Hidden extends WeForms_Field_Contract { |
| 7 |
|
| 8 |
public function __construct() { |
| 9 |
$this->name = __( 'Hidden Field', 'weforms' ); |
| 10 |
$this->input_type = 'custom_hidden_field'; |
| 11 |
$this->icon = 'eye-slash'; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Render the text field |
| 16 |
* |
| 17 |
* @param array $field_settings |
| 18 |
* @param int $form_id |
| 19 |
* |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
public function render( $field_settings, $form_id ) { |
| 23 |
if ( isset( $field_settings['dynamic']['param_name'] ) ) { |
| 24 |
if ( isset( $_GET[ $field_settings['dynamic']['param_name'] ] ) ) { |
| 25 |
$value = sanitize_text_field( wp_unslash( $_GET[$field_settings['dynamic']['param_name']] ) ); |
| 26 |
} else { |
| 27 |
$value = $field_settings['meta_value']; |
| 28 |
} |
| 29 |
} else { |
| 30 |
$value = $field_settings['meta_value']; |
| 31 |
} |
| 32 |
?> |
| 33 |
<input type="hidden" name="<?php echo esc_attr( $field_settings['name'] ); ?>" value="<?php echo esc_attr( $value ); ?>"> |
| 34 |
<?php |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Get field options setting |
| 39 |
* |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
public function get_options_settings() { |
| 43 |
$settings = [ |
| 44 |
[ |
| 45 |
'name' => 'name', |
| 46 |
'title' => __( 'Meta Key', 'weforms' ), |
| 47 |
'type' => 'text', |
| 48 |
'section' => 'basic', |
| 49 |
'priority' => 10, |
| 50 |
'help_text' => __( 'Name of the meta key this field will save to', 'weforms' ), |
| 51 |
], |
| 52 |
[ |
| 53 |
'name' => 'meta_value', |
| 54 |
'title' => __( 'Meta Value', 'weforms' ), |
| 55 |
'type' => 'text', |
| 56 |
'section' => 'basic', |
| 57 |
'priority' => 11, |
| 58 |
'help_text' => __( 'Enter the meta value', 'weforms' ), |
| 59 |
], |
| 60 |
[ |
| 61 |
'name' => 'dynamic', |
| 62 |
'title' => '', |
| 63 |
'type' => 'dynamic-field', |
| 64 |
'section' => 'advanced', |
| 65 |
'priority' => 23, |
| 66 |
'help_text' => __( 'Check this option to allow field to be populated dynamically using hooks/query string/shortcode', 'weforms' ), |
| 67 |
], |
| 68 |
]; |
| 69 |
|
| 70 |
return $settings; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Get the field props |
| 75 |
* |
| 76 |
* @return array |
| 77 |
*/ |
| 78 |
public function get_field_props() { |
| 79 |
$props = [ |
| 80 |
'template' => $this->get_type(), |
| 81 |
'name' => '', |
| 82 |
'meta_value' => '', |
| 83 |
'is_meta' => 'yes', |
| 84 |
'id' => 0, |
| 85 |
'is_new' => true, |
| 86 |
'wpuf_cond' => null, |
| 87 |
]; |
| 88 |
|
| 89 |
return $props; |
| 90 |
} |
| 91 |
} |
| 92 |
|