- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 08:25 PM - edited 12-15-2023 08:59 PM
Hi,
When user tries to submit the form from portal, how to prevent users from entering certain words/phrases into a text field.
Eg:- Testing, Test, Food
Thanks in advance.
Thanks,
Anoja
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 08:54 PM - edited 12-15-2023 09:12 PM
Hi @Anoja ,
U can try below code. Please create an onSubmit script for this
function onSubmit() {
// Get the value of the text field
var textFieldValue = g_form.getValue('your_text_field_name'); // Replace 'your_text_field_name' with the actual field name
// Check if the entered value contains the restricted word/phrase
if (textFieldValue.toLowerCase().includes('testing')) {
// Display an error message
alert('Sorry, you cannot enter the word "Testing". Please choose a different value.');
// Prevent form submission
return false;
}
// Continue with the form submission
return true;
}
You can also use above code in onChange client script as well.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 09:09 PM
Hello @Anoja ,
You can create a onSubmit client script to restrict the user from submitting the form as below:
function onSubmit() {
//Type appropriate comment here, and begin script below
var val = g_form.getValue('software_requirements'); // get the value of field.
var disallowedWords = ['Charger','Headphone', 'Testing]; // Array of words and phrases that needs to be prevented.
for (var i = 0; i < disallowedWords.length; i++) {
if (val.indexOf(disallowedWords[i]) !== -1) {
// Display an error message
g_form.addErrorMessage("The text field cannot contain '" + disallowedWords[i] + "'.");
g_form.clearValue('software_requirements');
return false; //Prevent Submission
}
} return true; // Allow to submit
}
This script worked for me. If it solves your issue, please mark it as Helpful 👍 and Accepted ✔️ based on impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 08:54 PM - edited 12-15-2023 09:12 PM
Hi @Anoja ,
U can try below code. Please create an onSubmit script for this
function onSubmit() {
// Get the value of the text field
var textFieldValue = g_form.getValue('your_text_field_name'); // Replace 'your_text_field_name' with the actual field name
// Check if the entered value contains the restricted word/phrase
if (textFieldValue.toLowerCase().includes('testing')) {
// Display an error message
alert('Sorry, you cannot enter the word "Testing". Please choose a different value.');
// Prevent form submission
return false;
}
// Continue with the form submission
return true;
}
You can also use above code in onChange client script as well.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 09:01 PM - edited 12-15-2023 09:02 PM
Hi @Danish Bhairag2 , Can we write business rule for multiple keywords?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 09:07 PM
Hi @Anoja ,
The BR would be for storing multiple Keywords?
I think that will not be helpful as I feel it will be challenge to call a BR when u doing something on portal form level. As BR executed Mostly on Insert Update of the Backend records.
You can use a system property instead to store multiple values as comma separated n then query that in your logic. You need to call a script include using Glide Ajax to execute system property command & validate der.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 09:09 PM
Hello @Anoja ,
You can create a onSubmit client script to restrict the user from submitting the form as below:
function onSubmit() {
//Type appropriate comment here, and begin script below
var val = g_form.getValue('software_requirements'); // get the value of field.
var disallowedWords = ['Charger','Headphone', 'Testing]; // Array of words and phrases that needs to be prevented.
for (var i = 0; i < disallowedWords.length; i++) {
if (val.indexOf(disallowedWords[i]) !== -1) {
// Display an error message
g_form.addErrorMessage("The text field cannot contain '" + disallowedWords[i] + "'.");
g_form.clearValue('software_requirements');
return false; //Prevent Submission
}
} return true; // Allow to submit
}
This script worked for me. If it solves your issue, please mark it as Helpful 👍 and Accepted ✔️ based on impact.
Thanks