API_Action::handle( awsmug\Torro_Forms\DB_Objects\Submissions\Submission $submission, awsmug\Torro_Forms\DB_Objects\Forms\Form $form )

Handles the action for a specific form submission.

Description

See also

Parameters

$submission

(awsmug\Torro_Forms\DB_Objects\Submissions\Submission) (Required) Submission to handle by the action.

$form

(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form the submission applies to.

Return

(bool|WP_Error) True on success, error object on failure.

Source

File: src/modules/actions/api-action.php

	public function handle( $submission, $form ) {
		$form_options      = $this->get_form_options( $form->id );
		$submission_values = $submission->get_submission_values();

		$meta_map_fields = $this->get_meta_map_fields();

		$mappings = $this->get_mappings( $form->id );

		try {
			$request = $this->api()->get_request_object( $this->api_route_uri, $this->api_request_method );

			foreach ( $form_options as $key => $value ) {
				if ( ! isset( $meta_map_fields[ $key ] ) ) {
					continue;
				}

				if ( empty( $value ) ) {
					continue;
				}

				$request->set_param( $key, $value );
			}

			foreach ( $submission_values as $submission_value ) {
				if ( ! isset( $mappings[ $submission_value->element_id ] ) ) {
					continue;
				}

				$field = ! empty( $submission_value->field ) ? $submission_value->field : '_main';
				if ( ! isset( $mappings[ $submission_value->element_id ][ $field ] ) ) {
					continue;
				}

				if ( empty( $submission_value->value ) ) {
					continue;
				}

				$request->set_param( $mappings[ $submission_value->element_id ][ $field ], $submission_value->value );
			}

			$response = $this->module->apiapi()->send_request( $request );
		} catch ( Exception $e ) {
			return $this->process_error_response( $e, $submission, $form );
		}

		return $this->process_response( $response, $request, $submission, $form );
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.