Skip to content
PHP Logo

How can a PHP form be modified to ensure that only results with a URL in the "archiv_link" field are displayed, regardless of other form inputs?

To ensure that only results with a URL in the "archiv_link" field are displayed, you can modify the PHP form processing code to check if the input in the "archiv_link" field is a valid URL using the filter_var() function with the FILTER_VALIDATE_URL flag. If the input is a valid URL, then the result will be displayed; otherwise, it will be skipped.

php
// Check if the input in the "archiv_link" field is a valid URL
if (filter_var($_POST['archiv_link'], FILTER_VALIDATE_URL)) {
    // Display the result if the input is a valid URL
    echo "Result: " . $_POST['archiv_link'];
} else {
    // Skip displaying the result if the input is not a valid URL
    echo "Invalid URL input.";
}