Attribute validation with global code

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Bernie
User
Posts: 17

Attribute validation with global code

Post by Bernie »

Greetings.
I've been searching the forums, and haven't found the answer for my questions, so, here they go.
I'd like to validate a field FieldB based on two items:

  • The value of a field FieldA previous to FieldB in the form
  • The JS function I've designed in Client Scripts > Global > Pages with header/footer > Global Code, wich returns true/false depending on the value of the field FieldB.

Any ideas on how to do this? Any way to either send the value of A to be evaluated on the function or to use the value directly from the php code? (the field A is named x_FieldA on the source code).


mobhar
User
Posts: 11784

Post by mobhar »

For validating values using PHP, you can use "Form_CustomValidate" server event that belongs either to "Add" or "Edit" page. For this, you have to enable server validation from "PHP" -> "General Options" -> "Validation" -> "Server-side".

You can also use "Form_CustomValidate" client script that belongs to either "Add" or "Edit" page if you want to validate the value using Javascript.

Read "Server Events and Client Scripts" in the help file for further information and example.


danielc
User
Posts: 1601

Post by danielc »

Add onchange event by Startup Script for your field A to trigger your js function. Also read: http://api.jquery.com/change/.


Bernie
User
Posts: 17

Post by Bernie »

mobhar and danielc, thanks for the prompt answer.
mobhar, I was trying something like that, but wasn't able to make it work. I'll try again.
danielc, I was looking for a solution more like yours, I'll give it a try for sure.


Bernie
User
Posts: 17

Post by Bernie »

Me and a friend came with a very simple solution.
Just looked at the source code of the page generated, and used the name x_ClientType of the field to get it's value. The JS function in the Global Code now starts like this:

function checkValues(varV){
var variableJQ = $("#x_ClientType").val();
if(variableJQ == 'VIP') {
...

It works just dandy.


Post Reply