Forums

Event Switcher to verify field.

eeavdc 13 Aug, 2015
Hello I am trying to verify a field with server side validation using Event Switcher. I am using the following code
<?php
if ( $form->data["serialnumber"] == 'xxxxxx???' ) { 
return success;
}else{
return "fail";
?>
The field name is serialnumber. and I just want to verify the first 6 characters. I am testing it out with just displaying a message, but nothing happens. In the Setup of the form everything is not green. The "On fail" part of the Event Switcher is red.
GreyHead 14 Aug, 2015
Hi eeavdc,

I can see a couple of problems here.

+ The quotes are missing round 'success' - though in practice you probably don't need that event

+ You can't use ??? as a wildcard in the PHP if statement.

Please try
<?php
if ( substr($form->data['serialnumber'], 0, 6) !== 'xxxxxx' ) { 
  return 'fail';
?>

Bob
eeavdc 14 Aug, 2015
Thanks for the assistance I used the substr function and the following code:
<?php
$serialnum = $form->data['serialnumber'];
if ( substr($serialnum, 0, 6) !== 'xxxxxx' )  {
  return 'fail'; }
else {
return 'success'; }

One other thing with the Event switcher and using it as custom validation is getting the error message response. Is it possible to get the same time of error message generated as the other validations do ( ie as red bubble above the field)?
GreyHead 15 Aug, 2015
Hi eeavdc,

I think that the red popups are set by the JavaScript validation and not by the serverside. You could add a JavaScript version of this as a custom validation if that would help.

Bob
chriso0258 17 Aug, 2015

One other thing with the Event switcher and using it as custom validation is getting the error message response. Is it possible to get the same time of error message generated as the other validations do ( ie as red bubble above the field)?


Hi eeavdc, hope I'm not intruding on the conversation.

I didn't like the idea of using JS only because if someone turns off JS. I used the following format in my event switcher to add a custom message that had a color background to highlight the message:

<h3><p style="text-align: center; background-color: #F2F274;">
<?php
// Mandatory Fields
$brandResult = preg_match('/^[\w -]+$/', $form->data[editList]['brand']);
if ($brandResult == 0){
   echo "Brand is a mandatory field. Make sure it is not empty.<br>Be sure you have only used allowed special characters.<p>";
   return "fail";
}

$modelResult = preg_match('/^[\w -]+$/', $form->data[editList]['model']);
if ($modelResult == 0){
   echo "Model is a mandatory field. Make sure it is not empty.<br>Be sure you have only used allowed special characters.<p>";
   return "fail";
}
?>
</h3></p>
This topic is locked and no more replies can be posted.