What are some alternative methods to achieve the same functionality of writing to a file without using hidden fields in PHP?

Using hidden fields in PHP to write data to a file can be a security risk as the data is exposed in the HTML source code. An alternative method to achieve the same functionality is to use server-side processing to handle the data and write it to a file securely without exposing it in the client-side code.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $data = $_POST['data'];
    
    // Write data to a file securely
    $file = fopen("data.txt", "w");
    fwrite($file, $data);
    fclose($file);
}
?>