I have a view which can either display a form for creating/editing record like below:
Create
<form action="http://localhost:8000/academics" method="post" class="form-horizontal" id = "add_academic_form" role="form">
or
Edit
<form action="http://localhost:8000/academics/1" method="put" class="form-horizontal" id = "edit_academic_form" role="form">
When the user first visit the page, if there was no record, then the create form is shown.
Once the user click 'next' button, ajax is use to submit the form and redirect to the next page. Once on the next page, if the user clicks 'previous button', he is redirect back to the previous page and now since there is a record, the edit form is shown populated with the just created resource.
This works well if I trust the user to use the different buttons provided (next and previous) but becomes a problem if the user first visit the page, click next to create record, and from the next page, hit the back button of the browser and click next again which inserts the record multiple times. How can I solve this problem?
I tried an approach like so which doesn't seems to work:
function tough_guy(){
location.reload()
window.location.href = data.redirect
}
- After ajax success, reload page (so that the form switch happens) and then redirect to next page. It only redirects but doesn't reload first.