feat(n8n Form Trigger Node): Improvements (#7571)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
Michael Kret
2023-12-13 17:00:51 +02:00
committed by GitHub
parent 26f0d57f5f
commit 953a58f18b
37 changed files with 1163 additions and 496 deletions

View File

@@ -385,6 +385,10 @@
</svg>
</a>
</div>
{{#if redirectUrl}}
<a id='redirectUrl' href='{{redirectUrl}}' style='display: none;'></a>
{{/if}}
<input id="useResponseData" style="display: none;" value={{useResponseData}} />
</section>
</div>
<script>
@@ -483,19 +487,42 @@
document.querySelector('#submit-btn').disabled = true;
document.querySelector('#submit-btn').style.cursor = 'not-allowed';
document.querySelector('#submit-btn span').style.display = 'inline-block';
fetch('#', {
fetch('', {
method: 'POST',
body: formData,
})
.then(async function (response) {
const data = await response.json();
data.status = response.status;
return data;
})
.then(function (data) {
if (data.status === 200) {
form.style.display = 'none';
document.querySelector('#submitted-form').style.display = 'block';
const useResponseData = document.getElementById("useResponseData").value;
if (useResponseData === "true") {
const text = await response.text();
let json;
try{
json = JSON.parse(text);
} catch (e) {}
if (json?.redirectURL) {
const url = json.redirectURL.includes("://") ? json.redirectURL : "https://" + json.redirectURL;
window.location.replace(url);
} else if (json?.formSubmittedText) {
form.style.display = 'none';
document.querySelector('#submitted-form').style.display = 'block';
document.querySelector('#submitted-content').textContent = json.formSubmittedText;
} else {
document.body.innerHTML = text;
}
return;
}
if (response.status === 200) {
const redirectUrl = document.getElementById("redirectUrl");
if (redirectUrl) {
window.location.replace(redirectUrl.href);
} else {
form.style.display = 'none';
document.querySelector('#submitted-form').style.display = 'block';
}
} else {
form.style.display = 'none';
document.querySelector('#submitted-form').style.display = 'block';
@@ -503,6 +530,8 @@
document.querySelector('#submitted-content').textContent =
'An error occurred in the workflow handling this form';
}
return;
})
.catch(function (error) {
console.error('Error:', error);