ANON_FR_SUBMITFORM::fr_submit_form( $entry, int $form_id,  $field_data_array )

Validation function when the trigger action is hit


Parameters Parameters

$form_id

(int) (Required) submitted form id.

$response

(array) (Required) response array.

$method

(Required)


Source Source

File: src/integrations/forminator/triggers/anon-fr-submitform.php

	public function fr_submit_form( $entry, $form_id, $field_data_array ) {
		$user_id = get_current_user_id();

		$args = [
			'code'    => $this->trigger_code,
			'meta'    => $this->trigger_meta,
			'post_id' => intval( $form_id ),
			'user_id' => intval( $user_id ),
		];

		$args = Automator()->process->user->maybe_add_trigger_entry( $args, false );

		//Adding an action to save contact form submission in trigger meta
		$recipes = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
		do_action( 'automator_save_forminator_form_entry', $form_id, $recipes, $args );

		if ( $args ) {
			foreach ( $args as $result ) {
				if ( true === $result['result'] ) {
					if ( ! empty( $field_data_array ) ) {
						$trigger_id     = (int) $result['args']['trigger_id'];
						$user_id        = (int) $user_id;
						$trigger_log_id = (int) $result['args']['get_trigger_id'];
						$run_number     = (int) $result['args']['run_number'];
						$meta_key       = (string) $this->trigger_meta;
						foreach ( $field_data_array as $entry_field ) {
							$field_meta = "{$trigger_id}:{$meta_key}:{$form_id}|" . $entry_field['name'];
							$insert     = [
								'user_id'        => $user_id,
								'trigger_id'     => $trigger_id,
								'trigger_log_id' => $trigger_log_id,
								'meta_key'       => $field_meta,
								'meta_value'     => maybe_serialize( $entry_field['value'] ),
								'run_number'     => $run_number,
							];
							Automator()->process->user->insert_trigger_meta( $insert );
						}
					}
					Automator()->process->user->maybe_trigger_complete( $result['args'] );
				}
			}
		}
	}