name = __( 'Text', 'weforms' );
$this->input_type = 'text_field';
$this->icon = 'text-width';
}
/**
* Render the text field
*
* @param array $field_settings
* @param int $form_id
*
* @return void
*/
public function render( $field_settings, $form_id ) {
$value = $field_settings['default']; ?>
print_list_attributes( $field_settings ); ?>>
print_label( $field_settings, $form_id ); ?>
help_text( $field_settings ); ?>
check_word_restriction_func(
$field_settings['word_restriction'],
'no',
$field_settings['name'] . '_' . $form_id
);
}
$mask_option = isset( $field_settings['mask_options'] ) ? $field_settings['mask_options'] : '';
if ( $mask_option ) {
?>
get_default_option_settings();
$default_text_options = $this->get_default_text_option_settings( true );
$check_duplicate = [
[
'name' => 'duplicate',
'title' => 'No Duplicates',
'type' => 'checkbox',
'is_single_opt' => true,
'options' => [
'no' => __( 'Unique Values Only', 'weforms' ),
],
'default' => '',
'section' => 'advanced',
'priority' => 23,
'help_text' => __( 'Select this option to limit user input to unique values only. This will require that a value entered in a field does not currently exist in the entry database for that field.', 'weforms' ),
],
];
$text_options = array_merge( $default_options, $default_text_options, $check_duplicate );
return apply_filters( 'weforms_text_field_option_settings', $text_options );
}
/**
* Get the field props
*
* @return array
*/
public function get_field_props() {
$defaults = $this->default_attributes();
$props = [
'word_restriction' => '',
'duplicate' => '',
];
return array_merge( $defaults, $props );
}
/**
* Prepare entry
*
* @param $field
*
* @return mixed
*/
public function prepare_entry( $field, $args = [] ) {
if( empty( $_POST[ '_wpnonce' ] ) ) {
wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
}
if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
}
$args = ! empty( $args ) ? $args : weforms_clean( $_POST );
return sanitize_text_field( trim( $args[$field['name']] ) );
}
}