I want a FormFunction
to show a history of inputs, by default an empty list. But once the submit is hit, the form should be reloaded with the history shown on top.
I can not deploy another form on submit.
The last input needs to be transferred via http request body, not in url parameters.
Here is my attempt:
CloudDeploy[
Delayed @ With[
{ inputList = ImportString[
FromCharacterCode[
HTTPRequestData[][["BodyBytes"]]/.{}->ToCharacterCode@"[]"
, "UTF8"
]
,"RawJSON"
]
}
, FormFunction[
{
Framed @ inputList
, "x" -> "Number"
}
, HTTPResponse[
ExportString[Append[inputList, #x],"RawJSON"] (*BODY, it needs to be in the body not url parameters*)
, <|
"Headers"->{ "Location" -> First@CloudObject@"temp/recursiveForm" }
, "StatusCode"->302
|>
, CharacterEncoding->None
]&
]
]
, "temp/recursiveForm"
, "Permissions"->"Public"
]
The form's submit function is a manually generated, in order to add body, http redirect response.
It does not work in a sense that the body appears to be empty after redirection.
It could be due to how browsers handle 302 but I am not sure. I am not sure if my approach is wrong, if it is a limitation of FormFunctions or any other reason.
Any feedback appreciated.