Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Enhancing a Simple PHP Application Adding Search: Controller & View Escaping Output Review

Talha Khalid
Talha Khalid
10,262 Points

Code Challenge Issue

Hello all, I keep getting a "To place text inside a text field, give a value attribute." I am but it keeps giving me an error message. Any ideas?

index.php
<?php

require_once("inc/config.php");

$search_term = "";
if (isset($_GET["s"])) {
    $search_term = trim($_GET["s"]);
    if ($search_term != "") {
        require_once(ROOT_PATH . "inc/products.php");
        $products = get_products_search($search_term);
    }
}

$pageTitle = "Search";
$section = "search";
include(ROOT_PATH . "inc/header.php"); ?>

    <div class="section shirts search page">

        <div class="wrapper">

            <h1>Search</h1>

            <form method="get" action="./">
                <input type="text" name="s" value= "<?php if (isset($search_term)) { echo htmlspecialchars($search_term); } ?>" >
                <input type="submit" value="Go">
            </form>

            <?php

                if ($search_term != "") {
                    if (!empty($products)) {
                        echo '<ul class="products">';
                        foreach ($products as $product) {
                            echo get_list_view_html($product);
                        }
                        echo '</ul>';
                    } else {
                        echo '<p>No products were found matching that search term.</p>';
                    }
                }

            ?>

        </div>

    </div>

<?php include(ROOT_PATH . "inc/footer.php"); ?>

2 Answers

Sascha Bratton
Sascha Bratton
3,671 Points

While I believe your answer is correct, in that it would work and meets HTML spec, unfortunately it seems Treehouse is a bit more strict.

The problem is the space between = " and the space between " >.

So it has to look like this:

<input type="text" name="s" value="<?php if (isset($search_term)) { echo htmlspecialchars($search_term); } ?>">
Talha Khalid
Talha Khalid
10,262 Points

Hey Sascha

I tried that and still got an error message. I think it may be a bug in the code Treehouse uses to check the answer. I typed it exactly the way it was shown in the video after the challenge and still got the same error

Sascha Bratton
Sascha Bratton
3,671 Points

I copied your code into the challenge and it rejected it. I then removed those two spaces, and it accepted the answer as correct.

I suppose it's possible there is some issue with your browser?

Talha Khalid
Talha Khalid
10,262 Points

Just tried it now and it worked! Very strange but Thanks for the help!