How to Redirect on Save of a Form

The "Save and exit" value determines where you want the system to automatically redirect when a user saves a form instead of staying on the same page. For example, you can redirect to the Kapp's home page. This is most effectively done in the bundle, in FormContainer.js. It is also important that you set up a way to create exceptions. In this example, there is an attribute Redirect After Save that can be added to the form and set to false to prevent a redirect.

export const handleCreated = props => (res, actions) => {
  // Prevent standard form behavior to prevent multiple requests to Request.
  actions.stop();

  // Handle case were form is saved.
  if (
    res.submission &&
   props.formPage === res.submission.currentPage &&
    redirectPredicate(window.K('form').attributes('Redirect After Save'))
  ) {
    props.push(`/kapps/${props.kappSlug}`);
  } else {
    props.push(
      res.submission.coreState === 'Submitted'
        ? `/kapps/${props.kappSlug}/requests/${res.submission.id}/confirmation`
        : `/kapps/${props.kappSlug}/requests/${res.submission.id}`,
    );
  }
};


export const handleUpdated = props => res => {
  // Handle case were form is saved.
  if (
    res.submission &&
    props.formPage === res.submission.currentPage &&
    redirectPredicate(window.K('form').attributes('Redirect After Save'))
  ) {
    props.push(`/kapps/${props.kappSlug}`);
  }
};