How can a default value be set in a form field in PHP to prepopulate the value when the form is loaded?

To set a default value in a form field in PHP, you can use a ternary operator to check if the field has been submitted. If it has not been submitted, you can set the default value. This way, when the form is loaded initially, the field will be prepopulated with the default value.

<form method="post">
    <input type="text" name="field_name" value="<?php echo isset($_POST['field_name']) ? $_POST['field_name'] : 'Default Value'; ?>">
    <input type="submit" value="Submit">
</form>