Skip to content
Advertisement

How to prevent user from modifying submitted value in the form?

I have a simple form that sends a value to controller:

JavaScript

This value will be static and this value cannot be modified. But of course it can be easily changed in Chrome dev tools.

How can I better implement this?

I though of doing validation like this:

JavaScript

But it doesn’t work:

JavaScript

What is good way of securing this value?

Advertisement

Answer

Make use of laravel form request to validate request payload.

You can create new form request via command

JavaScript

Then goto newly created file in appHttpRequests folder and write all the rules in here.

JavaScript

Use this StorePaymentRequest in preparePayment controller method.

JavaScript

Now, request will be able to come up here if it successfully passed the validation otherwise ValidationException will be thrown automatically.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement