jquery - HTML5 required input attribute lets me submit a form -
i have super simple form:
<form> <input name="name" placeholder="your name" required> <input name="email" type="email" placeholder="your email" required> <input type="submit" value="submit"> </form>
i'm submitting using jquery (coffeescript style):
$('form').submit (event) -> event.preventdefault() $.post('../mail.php', $('form').serialize(), (data) -> $('form')[0].reset ) .done -> ... .fail -> ... .always -> ...
in chrome (as in chrome canary) works charm, , won't let me submit form if of inputs empty (it displays "please fill out field" message, should). in lot of other browsers though (safari, webkit safari i.e.) lets me submit form inputs empty.
what problem be? i'm little worried event.preventdefault
, maybe stops browsers checking input
s?
you can't rely on support of required
yet (unfortunately). see: http://caniuse.com/#feat=form-validation can see safari not yet supporting api.
you shouldn't rely on after commonly used browser implemented either, malicous visitor might use non-default browser , skip these checks.
Comments
Post a Comment