ANON_WPFF_SUBFORM::wpffform_submit( $insert_data,  $data,  $form )

Validation function when the trigger action is hit


Parameters Parameters

$inser_data

(Required)

$data

(Required)

$form

(Required)


Source Source

File: src/integrations/wp-fluent-forms/triggers/anon-wpff-subform.php

	public function wpffform_submit( $insert_data, $data, $form ) {
		$user_id = get_current_user_id();

		if ( empty( $form ) ) {
			return;
		}
		$recipes = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
		$matches = $this->match_condition( $form, $data, $recipes );

		if ( ! $matches ) {
			return;
		}

		foreach ( $matches as $trigger_id => $match ) {
			if ( Automator()->is_recipe_completed( $match['recipe_id'], $user_id ) ) {
				continue;
			}
			$args = [
				'code'             => $this->trigger_code,
				'meta'             => $this->trigger_meta,
				'meta_key'         => $this->trigger_meta,
				'recipe_to_match'  => $match['recipe_id'],
				'trigger_to_match' => $trigger_id,
				'ignore_post_id'   => true,
				'user_id'          => $user_id,
			];

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

			if ( $result ) {
				foreach ( $result as $r ) {
					if ( true === $r['result'] ) {
						if ( isset( $r['args'] ) && isset( $r['args']['get_trigger_id'] ) ) {
							//Saving form values in trigger log meta for token parsing!
							$wp_ff_args = [
								'code'           => $this->trigger_code,
								'meta'           => $this->trigger_meta,
								'post_id'        => intval( $form->id ),
								'trigger_id'     => (int) $r['args']['trigger_id'],
								'meta_key'       => $this->trigger_meta,
								'user_id'        => $user_id,
								'trigger_log_id' => $r['args']['get_trigger_id'],
								'run_number'     => $r['args']['run_number'],
							];

							Automator()->helpers->recipe->wp_fluent_forms->extract_save_wp_fluent_form_fields( $data, $form, $wp_ff_args );

							$insert = [
								'user_id'        => $user_id,
								'trigger_id'     => (int) $r['args']['trigger_id'],
								'trigger_log_id' => $r['args']['get_trigger_id'],
								'meta_key'       => $this->trigger_meta . '_ID',
								'meta_value'     => intval( $form->id ),
								'run_number'     => $r['args']['run_number'],
							];

							Automator()->insert_trigger_meta( $insert );
							Automator()->process->user->maybe_trigger_complete( $r['args'] );
						}
					}
				}
			}
		}
	}