0

The verify.js documentation website (http://verifyjs.com/) makes it seem that, in order to get form validation on your site, all you have to do is:

  1. Link to the github-hosted library

<!-- Verify.js (with Notify.js included) --> <script src="//raw.github.com/jpillora/verifyjs/gh-pages/dist/verify.notify.min.js"></script>

  1. Make sure you have jQuery linked (of course!)

  2. Add validation rules, by putting data-validate="____" in form fields

However, I have done those 3 steps, yet the email I am trying to validate, at www.texasca.com/quote.php doesn't validate. As in, you can enter in an invalid email and nothing happens.

Am I missing something? I can't find anything on their provided documentation that will tell me what I am doing wrong.

My code relative to the problem is below.

Form field with the validation:

<p class="regular-content option-label">Email Address</p>
    <input class="quote-option" type="text" name="EmailAddress" data-validate="email" id="EmailAddress" required >

Including necessary Javascript:

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>   
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!-- Verify.js (with Notify.js included) -->
<script src="//raw.github.com/jpillora/verifyjs/gh-pages/dist/verify.notify.min.js"></script>

Thanks in advance!

Zach Cook
  • 604
  • 12
  • 33
  • http://stackoverflow.com/questions/17341122/link-and-execute-external-javascript-file-hosted-on-github Github serves the file as `text/plain`, meaning that your browser will interpret it as text, not Javascript. You should either host the file yourself or find another place to load it from. The first answer in the linked question has a suggestion. – Sverri M. Olsen May 04 '15 at 08:51

1 Answers1

3

Your browser refuse to execute script from raw.github.com because its MIME type ("text/plain") is not executable, and strict MIME type checking is enabled.


Why has this happend?

Because the verifyjs documentation is obsolete. Github is a GIT repository service and not a CDN solution. They want to avoid to a huge traffic to their servers due to referencing assets (css/js) directly to them, so they don't serve the correct MIME type.

Solution!

You must serve the text (in this case verify.notify.min.js) as a javascript file instead of text. There are more solutions. First is to host the file by yourself somewhere. Second is to use a service called RawGit.


How to do it with RawGit?

Replace the last line of your code <script src="//raw.github.com/jpillora/verifyjs/gh-pages/dist/verify.notify.min.js"></script> with <script src="https://rawgit.com/jpillora/verifyjs/gh-pages/dist/verify.notify.min.js"></script>.

Samuel O
  • 2,258
  • 1
  • 16
  • 26