Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid form resubmission in Play Framework 2.0

I have a basic POST form being submitted. Every time a form is submitted, a database is updated. If someone tries to refresh the page, you get a "Confirm form resubmission?". Is there anyway to avoid this? I know this is achievable with PHP but thats not an option here

Thanks!

like image 597
Omar Wagih Avatar asked Dec 05 '25 20:12

Omar Wagih


1 Answers

The action that accepts your form POST should commit the data to the database and then redirect to another action. That way, when the user hits refresh, they will only be reading data, not writing it.

Here's an example:

  public Result terminate(Long depositKey) throws Exception {
    depositsService.cancelScheduledDeposit(getCurrentUser().memberKey(), depositKey);
    return redirect(routes.ControllerFactory.deposits.terminateConfirmation(depositKey));
  }
like image 174
Samo Avatar answered Dec 08 '25 08:12

Samo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!