Disable or Block links entered in...

User 182385 Photo


Registered User
2 posts

Does anyone have a good way to disable or block links (URLs) from being entered in the comment fields of Web Form Builder contact forms?
Ingrid
User 187934 Photo


Senior Advisor
19,948 posts

Hi Ingrid,
Here's one way. I'm using the code to hide and disable the submit button if there's a link detected within a textarea named comments.
Paste this into a html element in your form. change the name of the textarea to match yours or change the textarea to input if your using a plain text input.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
var jQ = $.noConflict(true);
jQ(document).ready(function(){
jQ("textarea[name='comments']").change(function(){
var comments = jQ("textarea[name='comments']").val();

var urls = comments.match(/\b(http|https)?(:\/\/)?(\S*)\.(\w{2,4})(.*)/g);
console.log(urls);
if (jQ(urls).length > 0){
jQ(':input[type="submit"]').hide();
jQ(':input[type="submit"]').prop('disabled', true);
console.log("It has a link");
}else{jQ(':input[type="submit"]').prop('disabled', false);
jQ(':input[type="submit"]').show();
console.log("It doesn't have a link");
}
});
});
</script>

I wasn't totally sure on how you actually wanted handle the links within the comments.
Working here.
https://ericrohloff.com/coffeecup/ccfor … -comments/
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 182385 Photo


Registered User
2 posts

Thank you, just saw this, tested it and it works.

I might want a modification like to change the HIDE to showing an Error text where the Submit button was.
Ingrid

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.