We have installed ChronoForms v5 (on Joomla 3.4.8), and need to check that the input filed name "Member-Code" has one of three values "1001", "1002", or "1003" before the form can be submitted (any other input should error).
I understand that this can be accomplished with a JavaScript Custom Validation on the text input element for serverside validation; with a PHP equivalent to repeat the check using an Event Switcher action in the form On Submit event.
Could we see an example of the custom code(s) and configuration required to accomplish this?
Thanks in advance!
I understand that this can be accomplished with a JavaScript Custom Validation on the text input element for serverside validation; with a PHP equivalent to repeat the check using an Event Switcher action in the form On Submit event.
Could we see an example of the custom code(s) and configuration required to accomplish this?
Thanks in advance!
Hi Alairis,
You can do validation in two ways: clientside using JavaScript in the browser; and/or serverside using PHP in an Event Switcher action in the On Submit event.
Clientside validation should be thought of as helping the user complete the form correctly, it does not provide any security as users can turn JavaScript off. For security and true validation use Serverside checks.
Clientside: add a function name e.g. checkValue in the Custom function box at the bottom of the element Validation tab.
In the form On Load event add a Load JavaScript action with code like this:
Note, that this includes the codes in the page HTML for anyone who hunts for them. If this is a security issue then it is possible to use Ajax to do the check on the server without includes the codes in the HTML.
Serverside: Add an Event Switcher after any Captcha checks, add one event checkFail and code like this:
Bob
You can do validation in two ways: clientside using JavaScript in the browser; and/or serverside using PHP in an Event Switcher action in the On Submit event.
Clientside validation should be thought of as helping the user complete the form correctly, it does not provide any security as users can turn JavaScript off. For security and true validation use Serverside checks.
Clientside: add a function name e.g. checkValue in the Custom function box at the bottom of the element Validation tab.
In the form On Load event add a Load JavaScript action with code like this:
function checkValue(el) {
var value, check;
value = jQuery(el).val();
check = jQuery.inArray(value, ['1001', '1002', '1003']);
if ( check > -1 ) {
return true;
} else {
return false;
}
}
Add an error message in the Title box.
Note, that this includes the codes in the page HTML for anyone who hunts for them. If this is a security issue then it is possible to use Ajax to do the check on the server without includes the codes in the HTML.
Serverside: Add an Event Switcher after any Captcha checks, add one event checkFail and code like this:
<?php
if ( !in_array($form->data['input_name'], array('1001', '1002', '1003')) {
$app = \JFactory::getApplication();
$app->enqueueMessage('Please check the code');
return 'checkFail';
}
?>
In the checkFail event add an Event Loop action to re-load the form.
Bob
This topic is locked and no more replies can be posted.