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 trialRonny Rosabal
4,812 PointsText inside of the hidden label.
The text inside the hidden label is "Address" and I am wondering if robots check to see if that text is the same as the value of the name attribute in the associated input tag? Could I instead have "DO NOT FILL" in case it is visible to regular users?
1 Answer
manav
5,466 PointsYes, you can write "DO NOT FILL" instead of "Address" like below:
<tr style="display: none;">
<th>
<label for="address">DO NOT FILL</label>
</th>
<td>
<input type="text" name="address" id="address">
</td>
</tr>
But, I think it's better to take user's input for two basic reasons:
A form that says "DO NOT FILL" or "LEAVE ME BLANK" doesn't sound legit, especially to visually impaired users who are trusting screen readers for browsing. They may find it suspicious or confusing unless you explain the whole spam story.
If your form asks a simple question like "2+2" or "what's the current year", you are only improving your chances of fighting spam.
You can still keep this input field hidden as you don't want most visitors to see it anyway. This way you can address both users, those who see your page, and those who don't.
<?php
if ($_POST["answer"] != "" && $_POST["answer"] != date('Y')) {
echo "Your form submission has an error.";
exit;
}
?>
<tr style="display: none; visibility: hidden;">
<th>
<label for="answer">What is current year?</label>
</th>
<td>
<input type="text" name="answer" id="answer">
</td>
</tr>
Make sure you add the CSS property visibility: hidden along with display: none as some screen readers like Window-Eyes ignore the later.
Hope this helps!
Agustin Grube
39,278 PointsAgustin Grube
39,278 PointsYes that would work. Using hidden fields for bots that spam can be named anything.