Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Grav Assets Plugin

Started by Muut Archive 11 years ago · 4 replies · 223 views
11 years ago

I have a Registration from that uses some simple javascript code in the head of the page to validate the email address input field.

How do I get the code listed below into the head of my form.md file using the {assets:inline_js} function?

<script type="text/JavaScript">
// prepare the form when the DOM is ready
$(document).ready(function() {

$('#submit').click(function() {

TXT
$(".error").remove();
var hasError = false;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

var emailblockReg = /^([\w-.]+@(?!10minutemail.com)(?!10minutemail.net)(?!ano-mail.net)(?!20minutemail.com)(?!anonbox.net)(?!anoninbox.com)(?!asobo-dea.info)(?!binkmail.com)(?!bund.us)(?!byom.de)(?!caramail.com)(?!cool.fr.nf)(?!courriel.fr.nf)(?!discardmail.com)(?!dispostable.com)([\w-]+.)+[\w-]{2,4})?$/;

HTML
var emailaddressVal = $("#Email").val();
if(emailaddressVal == '') {
  $("#Email").after('<span class="error">Please enter your email!</span>');
  hasError = true;
} 

else if(!emailReg.test(emailaddressVal)) {
  $("#Email").after('<span class="error">Enter a valid email!</span>');
  hasError = true;
}

else if(!emailblockReg.test(emailaddressVal)) {
  $("#Email").after('<span class="error">No disposable email addresses!</span>');
  hasError = true
}

if(hasError == true) { return false; }

});

});
</script>

Thanks,

Brad

11 years ago

Should be something like this:

JS
{assets:inline_js}
$(document).ready(function() {
  $("a.external").attr("target","_blank");
});
{/assets}

No <script></script> tags needed.

11 years ago

It goes in the header of the form.md file?

Because when I do I get the following error:

Symfony \ Component \ Yaml \ Exception \ ParseException

Unable to parse at line 10 (near "{assets:inline_js}").

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1326 9 years ago
Archive · by Muut Archive, 9 years ago
2 921 9 years ago
Archive · by Muut Archive, 9 years ago
2 4050 9 years ago
Archive · by Muut Archive, 9 years ago
1 2928 9 years ago
Archive · by Muut Archive, 9 years ago
3 1107 9 years ago