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 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.