What are the best practices for validating input fields in PHP using HTML5 attributes?

When validating input fields in PHP using HTML5 attributes, it is important to utilize both client-side and server-side validation to ensure data integrity and security. HTML5 attributes such as "required", "pattern", and "maxlength" can help enforce specific rules on input fields before submitting the form. However, these validations should always be supplemented with server-side validation in PHP to prevent any malicious or incorrect data from being processed.

<form method="post" action="process_form.php">
  <label for="username">Username:</label>
  <input type="text" id="username" name="username" required pattern="[a-zA-Z0-9]+" maxlength="20">
  
  <label for="email">Email:</label>
  <input type="email" id="email" name="email" required>
  
  <input type="submit" value="Submit">
</form>