addon_settings = $this->get_settings_values(); $multi_id = $this->generate_multi_id(); if ( isset( $submitted_data['multi_id'] ) ) { $multi_id = $submitted_data['multi_id']; } unset( $submitted_data['multi_id'] ); $is_submit = ! empty( $submitted_data ); $current_data = array( 'webhook_url' => '', 'name' => '', ); if ( isset( $submitted_data['name'] ) ) { $submitted_data['name'] = sanitize_text_field( $submitted_data['name'] ); } forminator_addon_maybe_log( __METHOD__, $submitted_data ); $notification = array(); foreach ( $current_data as $key => $value ) { if ( isset( $submitted_data[ $key ] ) ) { $current_data[ $key ] = $submitted_data[ $key ]; } elseif ( isset( $this->addon_settings[ $multi_id ][ $key ] ) ) { $current_data[ $key ] = $this->addon_settings[ $multi_id ][ $key ]; } } $error_message = ''; $input_error_messages = ''; try { if ( $is_submit ) { $input_exceptions = new Forminator_Integration_Settings_Exception(); if ( empty( $current_data['name'] ) ) { $input_exceptions->add_input_exception( esc_html__( 'Please create a name for this Webhook integration', 'forminator' ), 'name' ); } $this->validate_and_send_sample( $submitted_data, $input_exceptions ); $this->addon_settings = array_merge( $this->addon_settings, array( $multi_id => array( 'webhook_url' => $submitted_data['webhook_url'], 'name' => $submitted_data['name'], ), ) ); $this->save_module_settings_values(); $notification = array( 'type' => 'success', 'text' => '' . $this->addon->get_title() . ' [' . esc_html( $submitted_data['name'] ) . '] ' . esc_html__( 'Successfully connected and sent sample data to your Webhook', 'forminator' ), ); } } catch ( Forminator_Integration_Settings_Exception $e ) { $input_error_messages = $e->get_input_exceptions(); } catch ( Forminator_Integration_Exception $e ) { $error_message = $e->get_error_notice(); } $buttons = array(); if ( $this->setup_webhook_url_is_completed( array( 'multi_id' => $multi_id ) ) ) { $buttons['disconnect']['markup'] = Forminator_Integration::get_button_markup( esc_html__( 'Deactivate', 'forminator' ), 'sui-button-ghost sui-tooltip sui-tooltip-top-center forminator-addon-form-disconnect', esc_html__( 'Deactivate Webhook from this Form.', 'forminator' ) ); } $buttons['next']['markup'] = '
' . Forminator_Integration::get_button_markup( esc_html__( 'Save', 'forminator' ), 'sui-button-primary forminator-addon-finish' ) . '
'; $help_message = esc_html__( 'Give your webhook integration a name and add the webhook URL.', 'forminator' ); return array( 'html' => '

' . esc_html__( 'Set Up Webhook', 'forminator' ) . '

' . $help_message . '

' . $error_message . '
' . ( isset( $input_error_messages['name'] ) ? '' . esc_html( $input_error_messages['name'] ) . '' : '' ) . '
' . ( isset( $input_error_messages['webhook_url_error'] ) ? '' . esc_html( $input_error_messages['webhook_url_error'] ) . '' : '' ) . ' ' . ( forminator_is_show_documentation_link() ? '
' . sprintf( /* translators: 1: article anchor start, 2: article anchor end. */ esc_html__( 'Check %1$sour documentation%2$s for more information on using webhook URLs for your preferred automation tools.', 'forminator' ), '', '' ) . '
' : '' ) . '
', 'redirect' => false, 'is_close' => ( $is_submit && empty( $error_message ) && empty( $input_error_messages ) ), 'buttons' => $buttons, 'has_errors' => ( ! empty( $error_message ) || ! empty( $input_error_messages ) ), 'notification' => $notification, ); } /** * Build seample data form current fields * * @return array */ private function build_form_sample_data() { $sample_data = $this->prepare_form_fields_data(); // send form title, date. $sample_data['form-title'] = $this->form_settings['formName']; $sample_data['entry-time'] = current_time( 'Y-m-d H:i:s' ); return $sample_data; } }