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
ryan champin
16,836 Pointscontact form echo on same page
im following the tutorial on php contact forms and when theres an error it echoes the error statement on a new page....how do i get it to just echo near the incorrect field?
1 Answer
Kazimierz Matan
13,257 PointsUse AJAX technology, but it is a higher level of difficulty.
HTML5 form inputs support "pattern" attribute, which takes regular expression and tests input against it. For instance this form...
<form>
<label>
Username (max. 8 characters):
<input type="text" name="your_name" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]{1,8}$" >
</label>
<input type="submit">
</form>
...will allow you to enter username of max. 8 alphanumerical characters. Form will not be submitted until you enter a proper value. Minus - different browsers implement this feature in different ways and there may be differences in look and content of warning message.