PHP Classes

Client validations not kicking off

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Upcoming Visual HTML ...  >  All threads  >  Client validations not kicking off  >  (Un) Subscribe thread alerts  
Subject:Client validations not kicking off
Summary:Server validations taking precedence over client validations
Messages:6
Author:Form Class
Date:2007-05-05 13:12:11
Update:2007-05-07 12:25:52
 

  1. Client validations not kicking off   Reply   Report abuse  
Picture of Form Class Form Class - 2007-05-05 13:12:11
Hi All,

I ran into this situation for the first time. I have a form with some columns with client and some others with server validations. When I submit the form, the columns with client validations are not kicking off. All columns are getting validated from the server until I fill in the columns with server validations with some data and then, if the columns with the client validations are still empty, they are kicking off. In essense, until all the columns with server validations are filled in, the columns with client validations are not kicking off. Even if there is one column with server validations, all columns with client/server validations are getting validated from the server. I was expecting the form to finish off with the columns with client validations "first" and then go after the other columns that have server validations, if any. This is a multi-page form situation and I checked the subform - it's always a valid subform.

Is this normal behavior or am I doing something wrong?

TIA

  2. Re: Client validations not kicking off   Reply   Report abuse  
Picture of Form Class Form Class - 2007-05-05 13:14:47 - In reply to message 1 from Form Class
By server validations, I mean setting ValidateOnlyOnServerSide to true.

  3. Re: Client validations not kicking off   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-05-05 21:47:13 - In reply to message 1 from Form Class
It is hard to understand what you mean without seeing an example.

Anyway, if you are using sub-forms, validations are only performed if the button that you used to submit has no associated sub-form or has the same sub-form name of the inputs you want to validate.

  4. Re: Client validations not kicking off   Reply   Report abuse  
Picture of Form Class Form Class - 2007-05-06 01:26:56 - In reply to message 3 from Manuel Lemos
Hi Manuel,

All the fields including the submit buttons on the page belong to the same subform. Here is my situation:

$input = array(
'TYPE'=>'TEXT',
'NAME' => 'Name',
'VALUE' => 'FGV',
'SubForm' => 'page1',
'ValidateOnlyOnServerSide' => 1,
'ValidateAsNotEmpty' => 1,
'ValidateAsNotEmptyErrorMessage' => 'Name required!');

$form->AddInput( $input );

$input = array(
'TYPE'=>'CHECKBOX',
'ID' => 'Optin',
'NAME' => 'Subscribe',
'CHECKED' => 1,
'SubForm' => 'page1',
'MULTIPLE'=> 1,
'ValidateAsSet' => 1,
'ValidateAsNotEmpty' => 1,
'ValidateAsNotEmptyErrorMessage' => 'Subscribe required!');

$form->AddInput( $input );

$input = array(
'TYPE'=>'CHECKBOX',
'ID' => 'Optout',
'NAME' => 'Subscribe',
'CHECKED' => 0,
'SubForm' => 'page1',
'MULTIPLE'=> 1);

$form->AddInput( $input );

$input = array(
'TYPE'=>'SUBMIT',
'NAME' => 'Submit',
'VALUE' => 'Submit',
'SubForm' => 'page1');

$form->AddInput( $input );

[NOTE: I typed the above without checking for syntax errors]

Now, if I submit the form without filling anything in the Name/Subscribe fields, the form is getting validated for both the fields by the server because the Name field has ValidateOnlyOnServerSide set to true. The client validation for the Subscribe field is not firing. However, if I fill-in some value in the Name field and submit the form, the client validation for Subscribe field is firing. This is happening particularly with checkboxes set to MULTIPLE. What I was expecting was the form to finish with the client validations for the fields and then go to server for backend validations, if any. It may increase the bandwidth if all the fields are to be validated by the server just because one or more fields are set to validate on the server.

Hope the above is clear.

How do I get the form to fire client validations (first) in all cases?

Regards,

  5. Re: Client validations not kicking off   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-05-06 03:19:23 - In reply to message 4 from Form Class
This is still confusing.

The class generates Javascript to validate the form on the browser side. If the browser side validation is not happening, that must be for some reason. It does not have anything to do with the fact that you have set one input to validate on the server side.

Possible reasons for not validating on the browser side as you expect can include errors adding the inputs to form or Javascript errors. It is hard to tell what is the problem unless you provide the actual script that you trying.

Anyway, if your script looks like you provided, keep in mind checkbox field TYPE attribute is in lower case, ValidateAsNotEmpty does not make sense for checkbox inputs, and ValidateAsSet requires that you specify the respective validation error message.

  6. Re: Client validations not kicking off   Reply   Report abuse  
Picture of Form Class Form Class - 2007-05-07 12:25:52 - In reply to message 5 from Manuel Lemos
Manuel,

Yes, the TYPE is in lower case with only ValidateAsSet in the original code (no ValidateAsNotEmpty).

I debugged the script using the process of elimination and narrowed down the issue to an external interface control that replaces textarea inputs and comes with an API to set focus to it on validation errors. The problem was, the method to set focus to it was not working at all and hence some JS errors that were supressing the other client validation errors which is why it was going to the server for all validations.

Thanks and regards,