How can the required attribute be added to a form field in PHP?
To add the required attribute to a form field in PHP, you can simply include it in the HTML form input tag. This attribute ensures that the field must be filled out before the form can be submitted. By adding the required attribute, you can enforce data validation on the client side before the form is submitted to the server.
<form action="submit.php" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<input type="submit" value="Submit">
</form>