Would you mind sharing the API you need to trigger on form submission? Not the access, just the endpoint and what data do you send? In this way I can help you achieve this much easily.
@dejan I’m still trying to understand if it’s feasible.
So, we offer a “document” download from our website, and we need to trigger an email to the client after he submits the form.
example: Modelo Contrato de Compra e Venda - Onepilot
I’m wondering if I could call the mailgun’s api, but for that I think is that I would expose my mailgun api key to the client because everything is javascript. Am I right?
Do you have any idea how to solve this?
Maybe could we do the download immediately instead of sending an email? Does divhunt support that?
Hi. Did anyone ever figure this out? I’m trying to do it today, along with making the form a modal pop-up and am running into dead-ends. Any ideas @dejan ?
If you’re ok using webhooks you can try creating an event (on form submit) with the below code. Just substitute in the Form ID of the form you’re using (usually a 4 number ID), and the endpoint for capturing the webook
const validIds = [YOUR FORM ID HERE];
if (validIds.includes(data.form.id)) {
const fields = data.form.fields;
fetch('YOUR WEBHOOK ENDPOINT HERE', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(fields),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
// Check the content type to decide if we should parse it as JSON or text
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
return response.json();
} else {
return response.text();
}
})
.then(data => {
console.log('Success:', data);
})
.catch(error => {
console.error('Error:', error);
});
}
Thanks. Yes. This is perfect.
As a workaround I had used an approach from the tutorial and displayed a hidden button which simply provided a download to the file, but this single step, rather than the double step approach is much cleaner.
Many Thanks!