How can default values be set for form inputs in PHP?

To set default values for form inputs in PHP, you can use the ternary operator to check if the input has been submitted. If it has not been submitted, you can set a default value for the input. This ensures that the form inputs will have a predefined value when the form is first loaded.

<?php
// Set default values for form inputs
$name = isset($_POST['name']) ? $_POST['name'] : 'John Doe';
$email = isset($_POST['email']) ? $_POST['email'] : 'example@example.com';
?>

<form method="post" action="">
    <input type="text" name="name" value="<?php echo $name; ?>">
    <input type="email" name="email" value="<?php echo $email; ?>">
    <button type="submit">Submit</button>
</form>