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

Solution provided for displaying value is giving error

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

It is complaining that 'value' should be used but i think the above solution should work

1 Answer

Hi Chetan,

Your solution could work, based on what is discussed in the challenge, the answer in this case would be:

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

You could also accomplish this with the ternary operator, for example:

<input type="text" name="s" value="<?php echo isset($search_term) ? $search_term : ''; ?>">

As you stated, there are other methods to accomplish this, but that would be difficult to cover all bases in a single lesson, instead the challenge is focusing on the method covered in the video.

Hope that helps!