Returning error message from custom app form_handler to form result page

  • We have a custom app which is using our api to post the form data to an external database. This works fine which is good.


    However in the event of the external api being down or if there are any server side validation error messages we would like to show these in the form results page so the user knows there was a problem.


    How can we return back a message from the custom apps form_handler method and then show it in the form results page?


    This is the form_handler method we are using :


    function custom_app_form_handler($SubmittedForm)


    Thanks

  • drewm

    Approved the thread.
  • You can use the throw_error() function. The first argument is the type of the error e.g. required . The second argument optionally can be the input field ID (defaults to all).


    PHP
    1. $SubmittedForm->throw_error('api');
    HTML
    1. <perch:error for="all" type="api">
    2. <p class="error">Sorry, we are not able to complete your request at this time.</p>
    3. </perch:error>