settingsDTO->getPixels() ) < 1 ) { return; } $this->setupEventListeners(); } public function setupEventListeners() { add_action( 'fluentform/submission_inserted', array( $this, 'contactForm' ), 10, 3 ); } // https://fluentforms.com/docs/fluentform_submission_inserted/ public function contactForm( $entryId, $formData, $form ) { $formSettings = $this->settingsDTO->getForm( $form->id, $this->pluginName ); // Send only matched fields $eventDto = new EventDTO( EventDTO::EVENT_LEAD ); $contentDto = new ContentDTO(); $posted_data = array(); foreach ( $formData as $key => $value ) { // Check if the key does not start with an underscore if ( strpos( $key, '_' ) !== 0 ) { // If it is an array, means that the input has some inputs. Iterate them if ( is_array( $value ) ) { foreach ( $value as $subKey => $subValue ) { $posted_data[ $subKey ] = $subValue; } } else { $posted_data[ $key ] = $value; } } } foreach ( $formSettings->getMatches() as $match ) { $val = $posted_data[ $match->getFormField() ]; $this->assignMatchedValue( $val, $match, $eventDto, $contentDto ); } $this->sendEvent( $eventDto ); } public function getForms() { if ( ! function_exists( 'fluentFormApi' ) ) { return; } $forms = array(); foreach ( \FluentForm\App\Models\Form::query()->get() as $form ) { $formId = $form->id; $fields = array(); $formApi = fluentFormApi( 'forms' )->form( $formId ); foreach ( $formApi->fields()['fields'] as $fieldSettings ) { if ( isset( $fieldSettings['fields'] ) ) { foreach ( $fieldSettings['fields'] as $field ) { $fields[] = array( 'name' => $field['attributes']['name'], 'label' => $field['settings']['label'], 'type' => isset( $field['attributes']['type'] ) ? $field['attributes']['type'] : $field['element'], ); } } else { $fields[] = array( 'name' => $fieldSettings['attributes']['name'], 'label' => $fieldSettings['settings']['label'], 'type' => isset( $fieldSettings['attributes']['type'] ) ? $fieldSettings['attributes']['type'] : $fieldSettings['element'], ); } } $forms[] = array( 'id' => $formId, 'title' => $form->title, 'plugin' => $this->pluginName, 'fields' => $fields, ); } return $forms; } } }