How can the code be modified to handle different field names for form inputs?

To handle different field names for form inputs, you can use an associative array to map the field names to their corresponding values. This way, you can dynamically process the form inputs without hardcoding specific field names in the code.

<?php
// Define an associative array to map field names to their values
$field_names = array(
    'name' => $_POST['name'],
    'email' => $_POST['email'],
    'message' => $_POST['message']
);

// Loop through the field names array to process the form inputs
foreach($field_names as $field_name => $value) {
    // Process each field name and its corresponding value
    echo "Field Name: $field_name, Value: $value <br>";
}
?>