Elem_Tokens::elem_save_form_entry( $record,  $recipes,  $args )

Save form entry in meta.


Parameters Parameters

$form_id

(Required)

$recipes

(Required)

$args

(Required)


Top ↑

Return Return

(null|string)


Source Source

File: src/integrations/elementor/tokens/elem-tokens.php

	public function elem_save_form_entry( $record, $recipes, $args ) {
		$form_id   = $record->get_form_settings( 'id' );
		$form_name = $record->get_form_settings( 'form_name' );
		$data      = $record->get( 'sent_data' );
		if ( ! empty( $data ) ) {
			$data = serialize( $data );
		}
		if ( is_array( $args ) ) {
			foreach ( $args as $trigger_result ) {
				if ( true === $trigger_result['result'] ) {

					if ( $recipes && ! empty( $form_id ) ) {
						foreach ( $recipes as $recipe ) {
							$triggers = $recipe['triggers'];
							if ( $triggers ) {
								foreach ( $triggers as $trigger ) {
									$trigger_id = $trigger['ID'];
									if ( ! key_exists( 'ELEMFORM', $trigger['meta'] ) ) {
										continue;
									} else {
										// Only form entry id will be saved.
										$user_id           = (int) $trigger_result['args']['user_id'];
										$recipe_log_id_raw = isset( $trigger_result['args']['recipe_log_id'] ) ? (int) $trigger_result['args']['recipe_log_id'] : Automator()->maybe_create_recipe_log_entry( $recipe['ID'], $user_id );
										if ( $recipe_log_id_raw ) {
											$trigger_log_id = (int) $trigger_result['args']['get_trigger_id'];
											$run_number     = (int) $trigger_result['args']['run_number'];
											$args           = [
												'user_id'        => $user_id,
												'trigger_id'     => $trigger_id,
												'meta_key'       => 'ELEMFORM_' . $form_id,
												'meta_value'     => $data,
												'run_number'     => $run_number, //get run number
												'trigger_log_id' => $trigger_log_id,
											];
											Automator()->insert_trigger_meta( $args );
											// For form name
											$args = [
												'user_id'        => $user_id,
												'trigger_id'     => $trigger_id,
												'meta_key'       => 'ELEMFORM_ELEMFORM',
												'meta_value'     => $form_name,
												'run_number'     => $run_number, //get run number
												'trigger_log_id' => $trigger_log_id,
											];

											Automator()->insert_trigger_meta( $args );
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}