if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit'])) { // form was submitted if (is_valid()) { // perform action, such as saving to a database } else { // display error message to user } }
function is_valid_email($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); } if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['email'])) { // form was submitted if (is_valid_email($_POST['email'])) { // email is valid, perform action } else { // email is invalid, display error message to user } }In this example, the `is_valid_email` function uses the built-in `FILTER_VALIDATE_EMAIL` filter to validate an email address. The form then checks if the email field was submitted and if it is valid using the `is_valid_email` function. Package Library: While PHP does not have a specific package or library for using `is_valid`, there are many third-party libraries available for form validation, such as voku/validator and Respect\Validation.