What is the best practice for allowing external users to submit entries to a search engine through a PHP form?

The best practice for allowing external users to submit entries to a search engine through a PHP form is to validate and sanitize the input data to prevent any security vulnerabilities such as SQL injection or cross-site scripting attacks. Additionally, it is important to properly handle errors and provide feedback to the user on the submission process.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Validate and sanitize input data
    $search_query = filter_var($_POST["search_query"], FILTER_SANITIZE_STRING);

    // Process the search query
    // Add your search engine logic here

    // Provide feedback to the user
    echo "Search query submitted successfully!";
}
?>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
    <label for="search_query">Search Query:</label>
    <input type="text" id="search_query" name="search_query">
    <button type="submit">Submit</button>
</form>