name = __( 'Date / Time', 'weforms' );
$this->input_type = 'date_field';
$this->icon = 'calendar-o';
}
/**
* Render the text field
*
* @param array $field_settings
* @param int $form_id
*
* @return void
*/
public function render( $field_settings, $form_id ) {
$value = ''; ?>
print_list_attributes( $field_settings ); ?>>
print_label( $field_settings ); ?>
help_text( $field_settings ); ?>
get_default_option_settings();
$settings = [
[
'name' => 'format',
'title' => __( 'Date Format', 'weforms' ),
'type' => 'text',
'section' => 'advanced',
'priority' => 23,
'help_text' => __( 'The date format', 'weforms' ),
],
[
'name' => 'time',
'title' => '',
'type' => 'checkbox',
'is_single_opt' => true,
'options' => [
'yes' => __( 'Enable time input', 'weforms' ),
],
'section' => 'advanced',
'priority' => 24,
'help_text' => '',
],
[
'name' => 'is_publish_time',
'title' => '',
'type' => 'checkbox',
'is_single_opt' => true,
'options' => [
'yes' => __( 'Set this as publish time input', 'weforms' ),
],
'section' => 'advanced',
'priority' => 24,
'help_text' => '',
],
];
return array_merge( $default_options, $settings );
}
/**
* Get the field props
*
* @return array
*/
public function get_field_props() {
$defaults = $this->default_attributes();
$props = [
'format' => 'dd/mm/yy',
'time' => '',
'is_publish_time' => '',
];
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']] ) );
}
}