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 trial

PHP Build a Simple PHP Application Wrapping Up The Project Validating Contact Form Data

Hidden input for secure reasons

In the video, we use css to hide the input. Can we use the attribute input type="hidden" with the same effective result?

1 Answer

The type="hidden" in the form element will give it away. CSS hides it without any traces whatsoever unless the bot is smart enough to check CSS. But type="hidden" says it right there in the element, that this element is hidden. It marks the element for something different, and bots might take notice of that. Additionally, type="hidden" elements pass under the radar of most of your average users, and a bot wants to simulate that, so it probably won't touch those elements.

If you're looking to separate concerns a little more, you could always do style="display:none;" in that particular element you want to hide. That way, it doesn't occupy any space in your stylesheet. Bots probably won't be smart enough to check inline CSS, but if they are, it's a good shot that they'll be checking all CSS, and so the honeypot is broken in that case anyway.

TL;DR: You can't/shouldn't; use style="display:none;" in that element instead.

I'm not an expert in this, so if anyone wants to add something, go right ahead.