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 Using A Third-Party Library

Christian Damm
Christian Damm
26,486 Points

email validation without browser standards

We validate the email-address with PHPMailer method validateAddress($email)

if(!$mail->validateAddress($email)) {
        echo "Error: You must specify a valid eMail address.";
        exit;
    }

But when we use the input type email the browser checks it with its own functions.

3 Answers

Myroslav Tkachenko
Myroslav Tkachenko
10,581 Points

you can turn off browser "validation" with setting an novalidate attribute to the form tag:

<form action="" method="post" novalidate>
  ...

</form>
Logan R
Logan R
22,989 Points

If you are asking why validate when browsers will take care of it:

It is never safe to rely on browsers to do input checking. People have outdated browsers can get around this or malicious people who want to spam you will take advantage of this.

Christian Damm
Christian Damm
26,486 Points

Hi Logan, I would like to overwrite the browser messages with my error messages. Maybe it comes later with an other php course.

Christian Damm
Christian Damm
26,486 Points

That's it. But I guess it should be written in this way:

<form method="post" action="contact.php" novalidate="novalidate">

Anyway, thanks a lot.

Myroslav Tkachenko
Myroslav Tkachenko
10,581 Points

in HTML5 setting a novalidate attribute without a value is a perfectly valid way, but in previous HTML standards it's not.

UPD. anyway, in the previous versions of the HTML standards there was no novalidate arrtribute :)