feat(n8n Form Trigger Node): Option to remove attribution (#9162)

This commit is contained in:
Michael Kret 2024-04-19 11:26:19 +03:00 committed by GitHub
parent 85780eade5
commit 699fd70c24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 56 additions and 32 deletions

View file

@ -78,6 +78,7 @@ describe('n8n Form Trigger', () => {
//add optional submitted message
cy.get('.param-options').click();
getVisibleSelect().find('span').contains('Form Response').click();
cy.contains('span', 'Text to Show')
.should('exist')
.parent()

View file

@ -354,6 +354,7 @@
</div>
</div>
{{#if appendAttribution}}
<div class='n8n-link'>
<a href={{n8nWebsiteLink}} target='_blank'>
Form automated with
@ -385,6 +386,8 @@
</svg>
</a>
</div>
{{/if}}
{{#if redirectUrl}}
<a id='redirectUrl' href='{{redirectUrl}}' style='display: none;'></a>
{{/if}}

View file

@ -30,4 +30,5 @@ export type FormTriggerData = {
n8nWebsiteLink: string;
formFields: FormTriggerInput[];
useResponseData?: boolean;
appendAttribution?: boolean;
};

View file

@ -10,6 +10,7 @@ export const prepareFormData = (
testRun: boolean,
instanceId?: string,
useResponseData?: boolean,
appendAttribution = true,
) => {
const validForm = formFields.length > 0;
const utm_campaign = instanceId ? `&utm_campaign=${instanceId}` : '';
@ -28,6 +29,7 @@ export const prepareFormData = (
n8nWebsiteLink,
formFields: [],
useResponseData,
appendAttribution,
};
if (redirectUrl) {
@ -90,6 +92,7 @@ export async function formWebhook(context: IWebhookFunctions) {
let formSubmittedText;
let redirectUrl;
let appendAttribution = true;
if (options.respondWithOptions) {
const values = (options.respondWithOptions as IDataObject).values as IDataObject;
@ -103,6 +106,10 @@ export async function formWebhook(context: IWebhookFunctions) {
formSubmittedText = options.formSubmittedText as string;
}
if (options.appendAttribution === false) {
appendAttribution = false;
}
const useResponseData = responseMode === 'responseNode';
const data = prepareFormData(
@ -114,6 +121,7 @@ export async function formWebhook(context: IWebhookFunctions) {
mode === 'test',
instanceId,
useResponseData,
appendAttribution,
);
const res = context.getResponseObject();

View file

@ -81,7 +81,18 @@ const descriptionV2: INodeTypeDescription = {
responseMode: ['responseNode'],
},
},
options: [respondWithOptions],
options: [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
displayName: 'Append n8n Attribution',
name: 'appendAttribution',
type: 'boolean',
default: true,
description:
'Whether to include the link “Form automated with n8n” at the bottom of the form',
},
respondWithOptions,
],
},
],
};