Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialchetan gavankar
4,635 PointsSolution 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
mikes02
Courses Plus Student 16,968 PointsHi 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">
</form>
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!