Formsort
Search…
POST body
Passing data through the body of a HTTP request.
In addition to pre-populating answers using URL parameters, It's possible to POST form data into Formsort. This may be preferable, as answers will not appear within the URL at any point - POST bodies are part of the HTTP body and are encrypted with HTTPS.
To POST data, the user must navigate to the deployed URL of your flow with the answers as form data in the body of the form, using the answer variable name as the name of the input.
The POST must be a navigation request.
You cannot just POST form data to Formsort using AJAX and then redirect the user.

Example: POSTing from a <form>

Normally, when you access a page directly in a browser, or by clicking a link, the browser will send a GET request, which cannot contain a body.
On the other hand, when submitting a <form> in HTML, the browser will navigate with a POST method, which will actually redirect the user to that URL.
Here's a working example as a standalone html page, that would redirect the user to a flow with cat_name set to "Olivia" and the cat_color set to the selected values:
1
<!doctype html>
2
<body>
3
<!-- TODO: Set the `action` to the URL of your deployed form -->
4
<form
5
method="POST"
6
action="https://flow.formsort.com/client/CLIENT_ID/flow/FLOW_ID..."
7
>
8
<input name="cat_name" value="Olivia" />
9
<select name="cat_color" multiple>
10
<option value="gray">gray</option>
11
<option value="brown">brown</option>
12
<option value="red">red</option>
13
</select>
14
<input type="submit" value="Start flow" />
15
</form>
16
</body>
17
<html>
Copied!
Of course, you could also use non-hidden inputs if the data you wish to pass should be user editable.

Example: POSTing in javascript

If you cannot have a <form>, or it doesn't make sense for your UX, you can create a form element on the fly and synthetically submit it:
  1. 1.
    Build up a <form> in your click handler
  2. 2.
    Add the answers:
    • For questions that accept a single answer, such as text questions, use <input type="hidden">. Assign the answer's variable name as the element's name.
      • For questions that accept multiple answers, use a <select> element, adding each answer as an <option>. Assign the answer's variable name as the <select> element's name. Make sure the <select> has the multiple property set to true, and each <option> has the selected property set to true.
  3. 3.
    Finally, .submit() the form instance.
Here's a working example as a standalone html page, that would redirect the user to a flow with cat_name set to "Olivia":
index.html
1
<!doctype html>
2
<html>
3
<head>
4
<script>
5
// TODO: Set these to your own values
6
const clientId = 'YOUR_CLIENT';
7
const flowId = 'YOUR_FLOW_LABEL';
8
const variantId = 'YOUR_VARIANT_LABEL';
9
10
let flow_url = "https://flow.formsort.com"
11
flow_url += `/client/${clientId}`;
12
flow_url += `/flow/${flowId}`;
13
flow_url += `/variant/${variantId}`;
14
15
const answers = {
16
"cat_name": "Olivia",
17
"cat_color": ["gray", "brown"]
18
};
19
20
const handleFormRedirect = (e) => {
21
e.preventDefault();
22
23
// 1. Build up a <form>
24
const form = document.createElement('form');
25
form.method = "POST"
26
form.action = flow_url;
27
28
// 2. Add the answers as <input type=hidden>
29
Object.keys(answers).forEach((key) => {
30
// If the answer is an array, add as <select> with <options>s
31
if (Array.isArray(answers[key])) {
32
const select = document.createElement("select");
33
select.type === "hidden"
34
select.name = key;
35
select.multiple = true;
36
37
answers[key].forEach((answer) => {
38
const option = document.createElement("option");
39
option.value = answer;
40
option.selected = true;
41
select.options.add(option);
42
});
43
form.appendChild(select);
44
} else {
45
// If the answer is a single value, add as an <input>
46
const input = document.createElement("input");
47
input.type = "hidden";
48
input.name = key;
49
input.value = answers[key];
50
form.appendChild(input);
51
}
52
});
53
document.body.appendChild(form);
54
55
// 3. Submit the form instance
56
form.submit();
57
}
58
</script>
59
</head>
60
<body>
61
<a href="" onclick="handleFormRedirect(event)">Start flow</a>
62
</body>
63
<html>
Copied!

Pre-posting data for a responder UUID

In the future, we'd like to support pre-posting data for a responder UUID, so that you can POST data asynchronously before you actually navigate the user to the flow, at which point the data will be retrieved.
This is an unimplemented feature - chat us if you'd be interested in this.