__( 'Any Otter Form Submitted (site-wide)', 'advanced-form-integration' ), ); } // Get Otter Forms Fields function adfoin_otterforms_get_form_fields( $form_provider, $form_id ) { if ( $form_provider !== 'otterforms' || $form_id !== 'anyForm' ) { return; } return array( 'email' => __( 'Email', 'advanced-form-integration' ), 'name' => __( 'Name (best-effort, from a text field labeled "name")', 'advanced-form-integration' ), 'message' => __( 'Message (best-effort, from a textarea field)', 'advanced-form-integration' ), 'form_option_id' => __( 'Form Option ID (identifies which form config was used)', 'advanced-form-integration' ), 'record_id' => __( 'Form Record ID (Otter\'s own saved submission, if any)', 'advanced-form-integration' ), 'all_fields_json' => __( 'All Fields (JSON, for fields not listed above)', 'advanced-form-integration' ), ); } // Handle Otter Form Submission function adfoin_otterforms_handle_submission( $form_data ) { if ( ! is_object( $form_data ) || ! method_exists( $form_data, 'get_fields' ) ) { return; } $integration = new Advanced_Form_Integration_Integration(); $saved_records = $integration->get_by_trigger( 'otterforms', 'anyForm' ); if ( empty( $saved_records ) ) { return; } $fields = $form_data->get_fields(); $all_fields = array(); $name_guess = ''; $message_guess = ''; if ( is_array( $fields ) ) { foreach ( $fields as $field ) { if ( ! is_array( $field ) ) { continue; } $label = isset( $field['label'] ) ? $field['label'] : ''; $type = isset( $field['type'] ) ? $field['type'] : ''; $value = isset( $field['value'] ) ? $field['value'] : ''; if ( $label ) { $all_fields[ $label ] = $value; } $label_lower = strtolower( (string) $label ); if ( 'textarea' === $type ) { $message_guess = $value; } elseif ( 'email' !== $type && false !== strpos( $label_lower, 'name' ) ) { $name_guess = $value; } } } $posted_data = array( 'email' => method_exists( $form_data, 'get_first_email_from_input_fields' ) ? $form_data->get_first_email_from_input_fields() : '', 'name' => $name_guess, 'message' => $message_guess, 'form_option_id' => method_exists( $form_data, 'get_form_option_id' ) ? $form_data->get_form_option_id() : '', 'record_id' => method_exists( $form_data, 'get_record_id' ) && $form_data->has_record_id() ? $form_data->get_record_id() : '', 'all_fields_json' => wp_json_encode( $all_fields ), ); adfoin_dispatch_integrations( $saved_records, $posted_data ); }