Submission_Manager::set_initial_submission_data( awsmug\Torro_Forms\DB_Objects\Submissions\Submission $submission, awsmug\Torro_Forms\DB_Objects\Forms\Form $form )

Sets the initial data for a new submission.

Description

It also stores the user key in session storage for the most basic user identification.

See also

Parameters

$submission

(awsmug\Torro_Forms\DB_Objects\Submissions\Submission) (Required) Submission object.

$form

(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form object.

Source

File: src/db-objects/submissions/submission-manager.php

	public function set_initial_submission_data( $submission, $form ) {
		$submission->form_id   = $form->id;
		$submission->status    = 'progressing';
		$submission->timestamp = current_time( 'timestamp', true );

		if ( is_user_logged_in() ) {
			$submission->user_id = get_current_user_id();
		}

		if ( ! empty( $_COOKIE['torro_identity'] ) ) {
			$submission->user_key = esc_attr( wp_unslash( $_COOKIE['torro_identity'] ) );
		} elseif ( isset( $_SESSION ) && ! empty( $_SESSION['torro_identity'] ) ) {
			$submission->user_key = esc_attr( wp_unslash( $_SESSION['torro_identity'] ) );
		} else {
			$base_string = ! empty( $_SERVER['REMOTE_ADDR'] ) ? $this->anonymize_ip_address( $_SERVER['REMOTE_ADDR'] ) . microtime() : microtime();
			$submission->user_key = md5( $base_string );
		}

		if ( ! isset( $_SESSION ) ) {
			if ( headers_sent() ) {
				return;
			}

			session_start();
		}

		$_SESSION['torro_identity'] = $submission->user_key;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.