arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Request From Web Form

A simple web form to send data to OpenEndpoints could look like this:

hashtag
What shall happen after submit?

The form calls your endpoint, which might for example

  • use an to forward an email to your back office, and also send a custom message to the email-address submitted with the form.

  • use an to send data to your CRM.

The behaviour of your web form after pressing the submit button depends on both the actions defined in your endpoint (success and error actions), and the html code in your web form.

hashtag
Option 1: Redirect to Success-Page / Error-Page

Configure your endpoint to redirect the request to a success or error page - see . Note that the absolute path to your page must be used, not a relative path.

On success (but not on error) you may use parameter placeholders. For example, you could add tracking information that is executed by your success page.

hashtag
Option 2: Return HTTP-Status

Omitting a particular action on success or failure will simply return a status code of 200 for success or 400 for any type of failure.

hashtag
Option 3: Return Custom JSON

If you want to return a user-defined JSON, then use a data source transformation to create that JSON using XSLT. For example, the JSON could contain some ID returned from your CRM (see: ):

Use an :

To output JSON, the XSLT should use the output method "text":

The transformer should explicitly define the content type "application/json":

hashtag
Option 4: Download Document

In case you use an having a download-filename attribute, the user will stay on the form, while the document is downloaded:

hashtag
Form Inputs vs Endpoint Parameters

The form entries are passed to the endpoint parameters. Depending on whether these parameters have a default value and whether a is used, different things must be observed:

hashtag
Option 1: Endpoint With Parameter Transformation

  • The name attributes in the web form can be completely different from the names of the endpoint parameters.

  • The parameter-transformation-xslt may only output parameter values of parameters that are declared in the endpoints.xml file. There are no restrictions as to how inputs from the web form are mapped with this output.

hashtag
Option 2: Endpoint Without Parameter Transformation

  • Input from the web form is passed to endpoint parameters only if the name attribute in the web form matches the name attribute of the endpoint parameter. Note that names are case sensitive.

  • Parameters without a default value must have an equivalent in the web form. Only parameters for which there is a default value are optional.

  • Inputs from web forms for which there is no corresponding parameter are silently ignored.

circle-exclamation

Potential Source of Error

OpenEndpoints parameter names are case sensitive. For example, if the name of the parameter is "firstname", then it will not match with "Firstname".

<form method="post" action="[path-to-endpoint]">
  <!-- include the "hash" param as a separate hidden field, or simply as GET parameter in the form-action -->
  <input type="hidden" name="hash" value="the-calculated-sha256-hash-code" />

  <!-- this can be "live" or "preview". If param is missing, default is "live". -->
  <input type="hidden" name="environment" value="preview" />

  <!-- only required to activate debug-mode -->
  <input type="hidden" name="debug" value="true" />

  <!-- name-attributes for web inputs = endpoint parameters -->
  <input type="..." name="firstname" /> <input type="..." name="lastname" />
  <input type="..." name="email" />

  <input type="submit" value="Send Request" />
</form>
The output generated by your XSLT requires values for any parameter not having a default value. Not doing so will raise an error.
Email Task
HttpRequest Task
Endpoint to Redirect Request
Intermediate Values
Endpoint to Return XSLT Transformation
Endpoint to Return XSLT Transformation
Parameter Transformation
<endpoint name="foo">
    <success>
        <redirect-to>https://myserver.com/path-to-success-page.html</redirect-to>
    </success>
    <error>
        <redirect-to>https://myserver.com/path-to-error-page.html</redirect-to>
    </error>
</endpoint>
<success>
  <redirect-to>https://myserver.com/page.php?something=${foo}</redirect-to>
</success>
<endpoint name="foo">
    <success/>
    <error/>
</endpoint>
{ "status": "ok", "customer-id": "12345" }
<endpoint name="foo">
    <success>
        <response-transformation name="custom-json"/>
    </success>
</endpoint>
<xsl:output method="text"/>
<transformer data-source="[name-of-data-source]">
    <xslt-file name="[path-to-xslt]"/>
    <content-type type="application/json"/>
</transformer>
<endpoint name="foo">
    <success>
        <response-transformation name="custom-document" download-filename="my-document.doc"/>
    </success>
</endpoint>