name = __( 'Multi Select', 'weforms' ); $this->input_type = 'multiple_select'; $this->icon = 'list-ul'; } /** * Render the text field * * @param array $field_settings * @param int $form_id * * @return void */ public function render( $field_settings, $form_id ) { $selected = isset( $field_settings['selected'] ) ? $field_settings['selected'] : ''; $selected = is_array( $selected ) ? $selected : []; $name = $field_settings['name'] . '[]'; ?>
  • print_list_attributes( $field_settings ); ?>> print_label( $field_settings, $form_id ); ?>
    help_text( $field_settings ); ?>
  • default_attributes(); $props = [ 'selected' => [], 'options' => [ 'Option' => __( 'Option', 'weforms' ) ], 'first' => __( '— Select —', 'weforms' ), ]; $props = apply_filters( 'weforms_multidropdown_field_props', $props ); 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 ); $entry_value = ( is_array( $args[$field['name']] ) && $args[$field['name']] ) ? $args[$field['name']] : array(); if ( $entry_value ) { $new_val = []; foreach ( $entry_value as $option_key ) { $new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : $option_key; } $entry_value = implode( WeForms::$field_separator, $new_val ); } else { $entry_value = ''; } return $entry_value; } }