The Illusion of Hiding Code in Client-Side Forms
You cannot hide form code from a browser's "Inspect Element" tool if that code resides within the HTML source served by your server. In the scenario you presented, the hidden inputs (id_crad, currency_code, amount) are rendered directly into the DOM before the user ever opens the page. Once an element exists in the Document Object Model (DOM), it is technically visible to any standard browser developer tool.
Attempting to obfuscate these fields by scrambling their names or adding excessive whitespace only delays a determined user who knows how to inspect the source, not prevents them. The underlying constraint is fundamental: if your server sends the form definition to the client, the client inherently possesses the ability to read that definition.
Why Client-Side Submission is Inherently Trustless
Your current implementation relies on setTimeout to trigger a form submission after three seconds. While this adds a visual loading delay, it does not secure the transaction. The browser executes the JavaScript provided by your server, submits the POST request, and displays the result. Because the payload (the hidden inputs) is visible in the network tab and the source code before submission, a developer can modify the amount value from 12.99 to 0.00 or alter the currency_code simply by editing the page source in their browser.
This is not a bug; it is the nature of HTTP and web forms. If you require sensitive dataâsuch as transaction amounts, user IDs, or security tokensâto remain hidden from the end-user during transit, you must never include that data in the HTML form itself for client-side rendering.
The Correct Architecture: Server-Side Generation
To achieve true privacy for form data, you must separate the presentation layer from the logic layer. The standard pattern for this is to generate the form entirely on the server using a templating engine that only renders the final HTML string after the sensitive values have been calculated or validated.
In a framework like Laravel, you would not write raw HTML strings with <form> tags directly in your view file if the data needs to be protected. Instead, you should use Blade directives:
// Example in a Laravel Controller or View
<form action="payments.php" method="POST">
@csrf
<input type="hidden" name="id_crad" value="{{ $id_crad }}">
<input type="hidden" name="currency_code" value="{{ $currency_code }}">
<input type="hidden" name="amount" value="{{ $amount }}">
</form>
Even with Blade, if the variables $amount etc., are passed directly from the database or a calculation that occurs on the client side, they remain visible in the source. The security boundary must be enforced at the server level after the request is received. When the user submits the form, your backend (payments.php) must validate these values against the original intent. If the user edits the amount field to 0, the server should reject it because the submitted value does not match the expected value derived from the session or a signed token.
Using Tokens Instead of Raw Values
If you need to send specific data without exposing the raw calculation logic, implement Signed Request Tokens. You generate a token on the server that encodes the necessary data (like amount and currency) along with a signature. This token is sent to the client as a single opaque string.
// Conceptual implementation of a signed token
$token = hash_hmac('sha256', json_encode(['amount' => $amount, 'currency' => $currency]), config('app.key'));
return view('redirect', ['token' => $token]);
In your HTML, you then render this token:
<input type="hidden" name="payment_token" value="{{ $token }}">
The client cannot inspect the original amount or currency because they are not present in the source. The server validates the signature upon receipt. If the user tries to manipulate the form, the signature will fail validation, and the request is rejected.
Handling the Redirect Delay
Your specific use case involves a waiting page with a loading GIF before redirecting or submitting. This pattern often introduces a vulnerability known as "time-of-check to time-of-use" if not handled carefully. If you rely on setTimeout to submit the form, and the user inspects the code, they can simply bypass the wait time by manually triggering the submission immediately.
A more robust approach for redirecting users is to use a server-side redirect (HTTP 302) rather than relying on client-side JavaScript to navigate away. If you must show a loading screen, ensure that the actual data processing happens server-side during that delay window, or use a signed token as described above so that the form data itself is not visible regardless of how quickly the user submits it.
Conclusion on Visibility
Ultimately, "hiding" code from inspect element tools in a web browser is a contradiction in terms for any data sent via standard HTTP requests. The only way to protect sensitive form data is to ensure the browser never receives the raw data in the first place. Use server-side generated HTML, implement server-side validation of all incoming data, and rely on cryptographic signatures to bind data to specific user sessions rather than trusting the client to display values correctly.
