سؤال

I'm using the PRG pattern in an application I'm building. There is a multi-page form where we validate and save the information in a database upon posting each page's form. If the submission passes validation then we redirect the user to the next page of the form. This works as you'd expect, and if the used hits the back button it goes to the pervious page with no resubmit warnings, etc.

Because the form is complex, in an effort to make it user friendly, when the validation fails we write the user's entries to $_SESSION and redirect them to the same page with appropriate messages. This works as well.

The issue is that if the user makes repeated posts that fail validation, the back button history gets loaded up with the same page, so they need to click the back button multiple times to get back to their expected previous page. What I'm looking for is a way to do something like javascript's window.location.replace when redirecting on failure so that the user won't have to hit the back button multiple times to get back to the previous page.

Is that possible in PHP with a header or will I need to use javascript to accomplish this?

هل كانت مفيدة؟

المحلول

One option would be to submit via AJAX for validation, if validation goes through correctly then actually submit page. Otherwise display error messages and stay on the same page.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top