Form redirect

Form redirect with dynamic api

Dynamic api uses a different kind of redirect from the models.

This redirect is only triggered if all the calls in the request succeed. If even one of them fails (errors model in the response contains something) then by default redirection is not triggered. However, there is a way to define optional requests that allowed to fail.

We define the redirection with Form.Redirect parameter The syntax here is exactly the same as with responses, only difference is that instead of the usual {{ and }} escapes we use [[ and ]] instead.

Use Form.AllowedToFailRequests input name to pass request names that allowed to fail and make redirect to the desired page even if they failed. Request names should be separated by comma (,)

<!-- Assign the first id from the response to the redirect link -->
<input type="hidden" name="Form.Redirect" value="da-dynamic-redirect?someParameter=[[ .Data.PIMApi.Api.Requests.request1.Response.Get `0.id` ]]">

Sample

<form method="get">
    <!-- For 'request1' use your own custom identifier, use it to access the results -->
    <input type="hidden" name="PIMApi.Api.Get.request1" value="/v1/product">

    <!-- Only redirects if all form containing requests succeed -->
    <input type="hidden" name="Form.Redirect" value="da-dynamic-redirect?wat=[[ .Data.PIMApi.Api.Requests.request1.Response.Get `0.id` ]]">
    <input type="hidden" name="Form.AllowedToFailRequests" value="request1">
    <button type="submit">Redirect on success</button>
</form>