Processing user submitted forms
Let's assume you want to give your customers an option to submit a form. Following submission form will be processed and a notification send to specified email address.
<form id="data" method="post" enctype="multipart/form-data" action="/apps/datajet/task/[your_task_id]">
<input type="text" name="first" value="">
<input type="text" name="last" value="">
<input type="file" name="photo" >
<button>Submit</button>
</form>
<script>
let form = document.querySelector("form#data");
form.addEventListener("submit", function(event){
event.preventDefault();
fetch(form.action, {
method: "POST",
body: new FormData(form)
})
.then(response => response.json())
.then(data => alert(JSON.stringify(data)))
});
</script>Above code creates a simple form with 2 text input fields and one file input field. This form is submitted via Ajax call to DataJet endpoint (please note task id is missing, replace it with your own task id).
Next, lets create a HTTP task with following code:
This code:
Accepts form submission
Uploads attached file to your local storage
Prepares html template for email
Sends an email to address specified
Last updated