This topic is locked
[SOLVED]

Custom Validation Plugin

6/16/2022 5:12:30 PM
PHPRunner General questions
A
Ace Drummond author

I have two fields cell_phone and carrier.

I want to present error while user is inputting the data so that if cell_phone is entered they would see edit error that carrier is required.

Conversely if carrier is entered and there is no cell_phone enetered it would also present an error.

I wrote the following .js code (untested at this point)

function cell_ck(sVal)
{
// Get the data entered on the screen for both cell_phone and carrier

var ctrl_cell_phone = Runner.getControl(pageid, 'associate_first_name');
var cell_phone = ctrl_cell_phone.getValue();

var ctrl_carrier = Runner.getControl(pageid, 'associate_first_name');
var carrier = ctrl_carrier.getValue();

// If cell phone number present we must have a carrier specified
if (cell_phone != '' && carrier == '')
{
return 'Cell Phone Number Requires that a Carrier be specified';
}

// If carrier specified we must have a cell phone specified
if (carrier != '' && cell_phone == '')
{
return 'Carrier Present so you must specifiy a cell phone number';
}

return true;
}

I then followed the manual and placed this in the directory where phprunner is installed C:\Program Files (x86)\PHPRunner10.7\source\include\validate

I am expecting it to show up in validate as dropdown in edit as screen, but it does not show up.

Can someone point me in the right direction?

A
Ace Drummond author 6/23/2022

In the phprunner manual there is a 'Validate As' option within the part about 'Validation Types' / 'How to add a custom validation plugin'

It directs us to place a .js function within the PHP Runner install folder in my case: C:\Program Files (x86)\PHPRunner10.7\source\include\validate

When I go in there initially there is a pre-exisiting test.js already there.

The problem as I am experiencing it is that the test.js does not show up in the validate as drop down nor does anything else I place in there show up.

I have restarted my computer as well as restarted phprunner no no avail.

While I've been able to handle my initial issue via other means I think this capability of a custom validation type would be very helpful.

My question right now is why does not even the included test.js show up in the validate as dropdown? or is this a feature that does not work?

M
macalister 6/24/2022

Hi

I think you are in wrong direction. "Validate As" is used to validate data format entered by user like zip codes, emails, etc.

In your case you can add this kind of validation in two ways.

  1. Validate fields on Javascript OnLoad event. You can play with "on" events like keyup, blur, click, change, etc you chan check this link for more info On Events
  2. Validate fields on Before record updated or Before record added. IE:

if(!empty($values["cell_phone "]) && empty($values["carrier "])){
$message = "Error Message";
return false;
}

if(empty($values["cell_phone "]) && !empty($values["carrier "])){
$message = "Error Message";
return false;
}
A
Ace Drummond author 6/24/2022

Thanks for your input.

I did utilize Before Record Added and that is done with php code not javascript.

That works; however, not giving me what I was trying to accomplish.

When you code it for instance as Before Record Added you do not see a message until you try to save the record - it shows up at the top of the screen in a red box. While that solves the immediate problem I was looking to have the error show up while editing the fields much as they do if you put an invalid resonce to one that is validated as a US zip code.

Looking at the maunual for phprunner it suggests one could develop javascript and add it to the default validate as dropdown and thus it would edit as hte field is entered vs. after you try to save the record.
see: phprunner manual there is a 'Validate As' option within the part about 'Validation Types' / 'How to add a custom validation plugin'

There is test.js in the directory by default, but it does not show up in the dropdown. It does get put into the uploaded /include/validate directory on the server; however, I do not see it showing up anywhere while I set up the screen or while I run the application.

If that would work as it seems to state in the manual one could develop a custom validate as javascript to add to the drop down and be reused very easily and no require you to place dode in many pages.

I just think I am missing something or I've stumbled on a feature that does not seem to work.

admin 6/25/2022

test.js is not supposed to show up in the 'Validate as' dropdown. However, if you follow an example in the manual, and add a new plugin, it wil show up.

One more thing. According to your message, you are adding this plugin to 32bit version of PHPRunner. If you, in fact, use 64bit version of PHPRunner, you won't see that plugin.

A
Ace Drummond author 6/25/2022

Thank you very much!

That explains the problem of getting this to show up.

I do have both a 32 bit and 64 bit version installed.

Now it does show up and I can work to perfect my validation.

I am relatively new to phprunner - do really like the product very much. I was using CodeCharge for many years and really had to move as there seems to be no future to that system.
Making lots of progress and some small things like this just take time.