APIs & Integrations

KMaslarski
Member

Prevent users from injecting hyperlinks in Form Fields

SOLVE

We are currently facing an issue with users trying to inject hyperlinks in form fields like first and last name, and currently, there is no solution from Hubspot. 

 

The AI support Chatbot asked me to use the following code to prevent this from happening: 

 

<script>document.addEventListener("DOMContentLoaded", function () { const form = document.querySelector('#formid'); if (!form) { console.log("Form not found."); return; } form.addEventListener('submit', function (e) { const inputs = form.querySelectorAll('input, textarea'); let valid = true; inputs.forEach(input => { console.log(`Checking input: ${input.value}`); const pattern = /https?:\/\/[^\s]+/; if (pattern.test(input.value)) { valid = false; alert('No hyperlinks allowed!'); console.log('Hyperlink detected:', input.value); } }); if (!valid) { console.log('Form submission blocked due to hyperlink.'); e.preventDefault(); } });});</script>

 

But sadly, it didn't work. Looking for any help to solve this issue. 

 

Thank you! 

0 Upvotes
1 Accepted solution
MichaelMa
Solution
Contributor

Prevent users from injecting hyperlinks in Form Fields

SOLVE

Do you have access to edit the property fields? You can put a rule on the property to disallow certain characters which would also be applied to forms, I believe.

 

Eg,

Property Rule:

MichaelMa_0-1745513434863.png

Form:

MichaelMa_1-1745513484207.png

 

 

View solution in original post

1 Reply 1
MichaelMa
Solution
Contributor

Prevent users from injecting hyperlinks in Form Fields

SOLVE

Do you have access to edit the property fields? You can put a rule on the property to disallow certain characters which would also be applied to forms, I believe.

 

Eg,

Property Rule:

MichaelMa_0-1745513434863.png

Form:

MichaelMa_1-1745513484207.png