Custom validation scripting code can be inserted to the Validation script box to prevent users from continuing, deciding what page to jump to, and for advanced question validation. The Validation script box is located on the right side of the screen when you select a Section break object. Press the JS/Perl button to toggle between JavaScript style and Perl style syntax. You can also view the Validation script box from the Validation tab of the advanced question options for Section break objects.
Custom JavaScript validation code is used in combination with the compiled CGIs. Custom Perl validation code is used in combination with the Perl CGIs.
All of the custom validation scripting code should be put into the projectname.val file.
if(condition)
{ [statements] } else (line break needed- nothing on this line after the else is evaluated) { (line break needed) [statements] (line break needed) } (space usually necessary) |
runReport
Process a .rep file and return the HTML code that it outputs.sendMail
Send an email message to the specified recipient. Note: the EMAILSERVER parameter must be in the .ini file for sendMail to know what email sever to use.ShowPage
Decide what page is shown next. The page name is going to be "page" then the name of the Section break that starts that page. For example, if the page I wanted to go to is named "P2", I would put in "pagep2". The last page of a multiple page survey does not check for the ShowPage; it will automatically submit.timestamp
The timestamp() function return the current time in the format YYYYMMDDHHMMSS.Send and Email
_msgtext = runReport('project.rep','project2.rep');
sendMail('raosoft@raosoft.com','EZSurvey submissions',_msgtext); |
Compound Conditional Validation
if(Q35 =='2')
{ if(/Q36/ ne '') {_PAGEWARN += 'notpossible,';} } |
Check-all-that-apply Validation (Make sure that no more than 3 boxes are selected.)
var _COUNTQ1 = 0;
if (/Q1/ eq '1') {_COUNTQ1 = _COUNTQ1 + 1;} if (/Q1/ eq '2') {_COUNTQ1 = _COUNTQ1 + 1;} if (/Q1/ eq '3') {_COUNTQ1 = _COUNTQ1 + 1;} if (/Q1/ eq '4') {_COUNTQ1 = _COUNTQ1 + 1;} if (/Q1/ eq '5') {_COUNTQ1 = _COUNTQ1 + 1;} if(_COUNTQ1 > 3) {_PAGEWARN += 'Q1,';} |
Rank Order Validation (Make sure that all 6 boxes are selected.)
var _COUNTQ3 = 0;
if(/Q3/ has '1') {_COUNTQ3 = _COUNTQ3 + 1;} if (/Q3/ has '2') {_COUNTQ3 = _COUNTQ3 + 1;} if (/Q3/ has '3') {_COUNTQ3 = _COUNTQ3 + 1;} if (/Q3/ has '4') {_COUNTQ3 = _COUNTQ3 + 1;} if (/Q3/ has '5') {_COUNTQ3 = _COUNTQ3 + 1;} if (/Q3/ has '6') {_COUNTQ3 = _COUNTQ3 + 1;} if(_COUNTQ3 < 6) {_PAGEWARN += 'Q3,';} |
Create a password for going to the next page in the survey.
var _pass = 0;
if (PASSWD eq 'test1'){_pass = 1;} if (PASSWD eq 'test2'){_pass = 1;} if(_pass ne 1) {_PAGEWARN += 'PASSWD';} |
Require that D1 have an answer and branch based off of the response to D1.
if (D1 eq '')
{_PAGEWARN += 'D1,';} if (_PAGEWARN eq '') { if (/D1/ eq '1BPO') {showpage('pageddbpo'); }if (/D1/ eq '2CD') {showpage('pageddcd'); }if (_PAGESKIP eq '' && _PAGENEXT eq '') {showpage('pageddbpo');}} |