Online Form Validation by ReCAPTCHA

There are instances where Online forms are vulnerable to BOT attacks, leading to the creation of multiple fraudulent LEAD records in NetSuite. One way to overcome this is to use ReCAPTCHA by Google, which protects websites from spam and abuse by distinguishing human users from automated bots. However, the said feature is an enhancement which is logged on enhancement #122792 Online Customer Forms > Spam getting through online customer forms and bad leads are getting created

One way to implement this, similar to ReCAPTCHA, is by creating a Custom Field and applying a script that determines what user input is based on what is shown in an image.

Learn to implement it by following the steps below. 

Create custom entity field of type free-form text 

  1. Set Label fieldOnline Form Ver Image 
  2. Set ID field: _verimage 
  3. Select Type dropdown field: Free-form Text 
  4. Store Value checkbox: Mark Checked 
  5. Applies To: Customer 
  6. Save the custom entity field. 

See sample image below: 

image-58ae6c28744298-45df.png

 

Upload images in the File Cabinet 

 

  1. Navigate to Documents > Files > File Cabinet 
  2. Navigate to Web Site Hosting Files > Live Hosting Files  
  3. Inside Live Hosting Files folder, add new folder and name it to OnlineForm 
  4. Inside the OnlineForm folder, upload the images you will use for your online form. See example below.

Sample Images

  1. – cat.jpg 
  2. – dog.jpg 
  3. – rabbit.jpg 
  4. – bird.jpg 

image-ff3ed4a753fca-b3aa.png

Edit your Online form Template by following the steps below: 

  1. Navigate to Documents > Templates > Marketing Templates. 
  2. Edit your Online form Template
  3. Add the needed lines of code below in the template in its corresponding tags (e.g. <head>) and make sure to replace the image links with ones you uploaded in the file cabinet.

Example:

From: <account_number>.app.netsuite.com/c.<account_number>/OnlineForm/cat.jpg

To: 1234567.app.netsuite.com/c.1234567/OnlineForm/cat.jpg

<NLFORM> 

<html> 

<head> 

 
<script language=”JavaScript”> 

 
var theImages = new Array() 
// url of the random images file hosted in the file cabinet 
theImages[0] = ‘https://<account_number>.app.netsuite.com/c.<account_number>/OnlineForm/cat.jpg’  
theImages[1] = ‘https://<account_number>.app.netsuite.com/c.<account_number>/OnlineForm/dog.jpg’ 
theImages[2] = ‘https://<account_number>.app.netsuite.com/c.<account_number>/OnlineForm/rabbit.jpg’ 
theImages[3] = ‘https://<account_number>.app.netsuite.com/c.<account_number>/OnlineForm/bird.jpg’ 

 
var j = 0 
var p = theImages.length; 
var rebuffer = new Array() 
for (I = 0; I < p; i++){ 
rebuffer[i] = new Image() 
rebuffer[i].src = theImages[i] 
} 

 
var whichImage = Math.round(Math.random()*(p-1)); 

 
function showImage() 
{ 
document.write(‘<img border=1 src=”’+theImages[whichImage]+’”>’); 
} 

 
</script> 

 

</head> 

 

<body> 

First Name*: <NLFIRSTNAME><br /> 

Last Name*: <NLLASTNAME><br /> 

Company Name: <NLCOMPANYNAME><br /> 

Phone Number: <NLPHONE><br /> 

Email Address: <NLEMAIL><br /><br /> 
<script language=”JavaScript”>showImage();</script><br /> 

Input the animal you see in the image: <NLCUSTENTITY_VERIMAGE> <br/> 

Note: Type the characters in lowercase 

<p> 

<input type=”submit” value=”Submit”> 

</p> 

</body> 

</html> 

</NLFORM> 

 

image-322eb6fc3381-9eb9.png

Set the Template for your Online Customer Form and add the custom entity field in the Select Fields tab then set it mandatory. 

 

  1. Navigate to Setup > Marketing > Online Customer Form 
  2. Edit your Online Customer Form 
  3. Template field: Select your Online Form Template 
  4. Select Fields tab: Add Online Form Ver image field – Set to Mandatory

 

image-d35940158961f8-9f6e.png

Add custom script and deploy to the online customer form calling the verification function on save. 

 

  1. Create a file in your computer and name it OnlineFormScript.js 

image-bf677bf187581-66fa.png

2.Edit the OnlineFormScript.js file and add the following lines of code below then save the file: 

Note: Replace the values (in RED) with the corresponding correct answers to identify the images in lowercase letters.  

function saveRecord(){ 
  var userInput = (String(nlapiGetFieldValue('custentity_verimage'))); 
   case (userInput = 'cat'): 
  if (whichImage == 0){return true;} 
    alert("Sorry, the image verification did not match"); 
    return false; 
  case (userInput = 'dog'): 
    if (whichImage == 1){return true;} 
    alert("Sorry, the image verification did not match"); 
    return false; 
  case (userInput = 'rabbit'): 
    if (whichImage == 2){return true;} 
    alert("Sorry, the image verification did not match"); 
    return false; 
  case (userInput = 'bird'): 
    if (whichImage == 3){return true;} 
    alert("Sorry, the image verification did not match"); 
    return false; 
  default: 
    alert("Sorry, the image verification did not match"); 
    return false; 
  }  
} 

 

  1. Navigate to Setup > Marketing > Online Customer Form 
  2. Edit your Online Customer Form 
  3. Custom Code tab 
  4. Upload the OnlineFormScript.js script file 
  5. Save Record Function field: Input saveRecord 
  6. Save your Online Customer Form. 

image-796d92f58b63f-3ec9.png

 

Actual Result of the implementation above: 

image-a4d174f7d320a8-e9ce.png

Leave a comment

Your email address will not be published. Required fields are marked *