protected function prepare_submitted_data( $fields, array $data, $clear_missing ) {
		$submitted = [];

		foreach ( $fields as $field ) {
			if ( $this->maybe_skip_field( $field ) ) {
				continue;
			}

			$value = array_key_exists( $field->get_id(), $data )
				? $data[ $field->get_id() ]
				: null;

			// Treat false as NULL to support binding false to checkboxes.
			// Don't convert NULL to a string here in order to determine later
			// whether an empty value has been submitted or whether no value has
			// been submitted at all. This is important for processing checkboxes
			// and radio buttons with empty values.
			if ( false === $value ) {
				$value = null;
			} elseif ( is_scalar( $value ) ) {
				$value = (string) $value;
			}

			// Perform the sanitization to get sanitized value.
			$sanitized = $field->get_sanitization_value( $value );

			if ( $field->is_group() ) {
				$submitted[ $field->get_id() ] = $this->get_group_values( $field, $sanitized );
			} else {
				$submitted[ $field->get_id() ] = $sanitized;
			}
		}

		// Clear "null" input data.
		if ( $clear_missing ) {
			$submitted = array_filter( $submitted, function ( $value ) {
				return ! is_null( $value );
			} );
		}

		return $submitted;
	}