How to redirect on save of a form

Redirect to another page when a form gets saved

Save and exit is where you want the system to automatically redirect, for example to the Kapp's home page, when a user saves instead of staying on the same 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 the 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}`);
  }
};

Did this page help you?