The CreatorCon Call for Content is officially open! Get started here.

Prevent certain words in portal

Anoja
Mega Sage

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

2 ACCEPTED SOLUTIONS

Danish Bhairag2
Tera Sage

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

 

View solution in original post

Vrushali  Kolte
Mega Sage

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
}

VrushaliKolte_0-1702703350474.png

 

This script worked for me. If it solves your issue, please mark it as Helpful 👍 and Accepted ✔️ based on impact.

Thanks

View solution in original post

4 REPLIES 4

Danish Bhairag2
Tera Sage

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

 

Hi @Danish Bhairag2 , Can we write business rule for multiple keywords?

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

 

Vrushali  Kolte
Mega Sage

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
}

VrushaliKolte_0-1702703350474.png

 

This script worked for me. If it solves your issue, please mark it as Helpful 👍 and Accepted ✔️ based on impact.

Thanks