In-Portal Issue Tracker - In-Portal CMS
Viewing Issue Advanced Details
271 [In-Portal CMS] Data Management feature request N/A 2009-09-04 15:28 2012-07-25 05:32
alex  
alex  
normal  
closed 5.1.0  
fixed  
 
none 5.2.0-B1  
https://groups.google.com/d/topic/in-portal-dev/cfhRH6VUxaE/discussion
3
0000271: Redesign "Data Validation" Engine
Here is form data processing cycle from user to database:

1. user opens editing template and inputs form data into form fields;
2. user presses save button to place it's changes to database;
3. form data is passed to kDBItem (or it's descendant) class for processing;
4. class kDBItem (or it's descendant) uses kDBItem::Validate method to validate data before saving to database;
5. internally validation is performed using options defined for each field in it's declaration (all fields are validated, no matter what fields were submitted from form);
6. based on validation results user is either returned to form with validation errors displayed or editing window is successfully closed.

This approach has several not obvious weaknesses:
1. all fields are validated, instead of submitted only fields - this takes time, when not all possible fields are displayed on form;
2. validation rules are defined directly in field declaration in unit config - this doesn't allow form-based validation rules on base level (but can be done inside event handler as usual).

Idea is to move all validation-related field options to form declaration (see task 0000270) and submit used form name along with form fields to kDBItem class, that will use it to perform form-based validation.

How to do this:
1. create kValidator class (with one public method named ValidateField) and move all validation-related code to it from kDBItem class;
2. add $form_name parameter to kDBItem::Validate and to kDBItem::ValidateField methods;
3. when $form_name parameter is not passed, then create (and cache) instance of kValidator class and use validation-related options from field declaration in unit config;
4. when $form_name parameter is passed, then create (and cache) instance of validator class, specified in form declaration and use validation-related options for given field from form declaration;
5. validate form fields using appropriate validator class and validation-related options.
4. create ValidatorClass unit config option (like ListClass option), that will allow to define custom validator class for given unit config and use it later in forms declared inside that unit config.

This way compatibility with unit configs, that don't use forms, layouts will be preserved. Also side effect is, that less memory will be used, when data from several tables in displayed on same screen (front-end mostly).
Form Usage:
===========
You can define as many forms as you need in 'Forms' unit config option, e.g.

'Forms' => Array (
    'front_registration' => Array (
        'Fields' => Array (
            'FirstName' => Array ('required' => 1, 'default' => ''),
        )
    ),
),

In this example new form called 'front_registration' is created. Database field called 'FirstName' is made required on this form. If form called 'default' is also defined, then it is always applied first.


You can override following unit config options from form declaration:
- ItemSQLs
- ListSQLs
- Fields
- CustomFields
- VirtualFields
- CalculatedFields
- AggregatedCalculatedFields


1. to set form name in template use this tag <inp2:prefix.special_FormName name="front_registration"/> before any other tag of this prefix.special.

2. to pass form-name to next template after form submit place this hidden field on a form:
<input type="hidden" name="forms[prefix.special]" value="<inp2:prefix.special_FormName/>"/>

3. to use custom validator class do this:
- add 'ValidatorClass' => 'CustomValidator' to unit config
- register class in factory
related to 0000951closed  (5.1.3)alex User isn't automatically logged-in, when "Immediate" user registration mode is used 
related to 0000270active  (Icebox) "Form Configuration" for Add/Edit in Admin Console 
related to 0000269active  (Icebox) "Form Layout" Configurator for Add/Edit Templates in Admin 
related to 0001095closed  (5.1.3)alex Error messages are displayed on unrelated forms 
related to 0000351active  (Icebox) Remove "kDBEventHandler::RemoveRequiredFields" method 
patch forms_core.patch (262,481) 2011-09-29 10:43
http://tracker.in-portal.org/file_download.php?file_id=1165&type=bug
patch forms_modules.patch (65,519) 2011-09-29 10:43
http://tracker.in-portal.org/file_download.php?file_id=1166&type=bug
patch forms_themes.patch (30,462) 2011-09-29 10:43
http://tracker.in-portal.org/file_download.php?file_id=1167&type=bug
patch session_expiration_used_validatelogin_field.patch (2,343) 2011-09-29 14:57
http://tracker.in-portal.org/file_download.php?file_id=1169&type=bug
patch user_autologin_after_registration_fix.patch (784) 2012-01-03 10:53
http://tracker.in-portal.org/file_download.php?file_id=1455&type=bug
Issue History
2012-07-25 05:32 alex Note Added: 0005006
2012-07-25 05:32 alex Status resolved => closed
2012-01-03 10:55 alex Changeset attached 5.2.x r14971
2012-01-03 10:53 alex File Added: user_autologin_after_registration_fix.patch
2011-10-22 05:36 alex Estimate Points => 3
2011-09-29 14:58 alex Changeset attached 5.2.x r14599
2011-09-29 14:57 alex File Added: session_expiration_used_validatelogin_field.patch
2011-09-29 10:46 alex Note Added: 0003937
2011-09-29 10:46 alex Status reviewed and tested => resolved
2011-09-29 10:46 alex Fixed in Version => 5.2.0-B1
2011-09-29 10:46 alex Resolution open => fixed
2011-09-29 10:46 alex Assigned To !COMMUNITY => alex
2011-09-29 10:46 alex Changeset attached 5.2.x r14596
2011-09-29 10:45 alex Changeset attached 5.2.x r14595
2011-09-29 10:45 alex Changeset attached 5.2.x r14594
2011-09-29 10:44 alex Changeset attached 1.2.x r14593
2011-09-29 10:44 alex Note Added: 0003936
2011-09-29 10:44 alex Status needs testing => reviewed and tested
2011-09-29 10:43 alex Time Estimate Removed 1 =>
2011-09-29 10:43 alex Note Added: 0003935
2011-09-29 10:43 alex Assigned To => !COMMUNITY
2011-09-29 10:43 alex Developer => alex
2011-09-29 10:43 alex Status active => needs testing
2011-09-29 10:43 alex File Added: forms_themes.patch
2011-09-29 10:43 alex File Added: forms_modules.patch
2011-09-29 10:43 alex File Added: forms_core.patch
2011-09-28 12:11 alex Note Edited: 0003755 bug_revision_view_page.php?bugnote_id=0003755#r856
2011-09-27 06:27 alex Time Estimate Added 1
2011-09-25 09:32 alex Relationship added related to 0000351
2011-09-17 05:07 alex Note Added: 0003755
2011-08-13 07:49 alex Additional Information Updated bug_revision_view_page.php?rev_id=797#r797
2011-08-10 05:08 alex Relationship added related to 0001095
2011-08-04 10:18 alex Relationship replaced related to 0000951
2011-08-04 10:18 alex Relationship added parent of 0000951
2011-07-28 04:02 alex Additional Information Updated bug_revision_view_page.php?rev_id=786#r786
2011-07-27 10:46 alex Note Edited: 0003642 bug_revision_view_page.php?bugnote_id=0003642#r784
2011-07-27 06:41 alex Note Edited: 0003642 bug_revision_view_page.php?bugnote_id=0003642#r783
2011-07-27 05:52 alex Note Added: 0003642
2011-07-08 10:58 alex Target Version Icebox => 5.2.0
2011-07-05 15:39 Dmitry Reference => https://groups.google.com/d/topic/in-portal-dev/cfhRH6VUxaE/discussion
2010-08-31 14:26 alex version => 5.1.0
2009-09-05 09:15 alex Summary Redesign "Data Dalidation" Engine => Redesign "Data Validation" Engine
2009-09-04 17:14 Dmitry Fixed in Version Icebox =>
2009-09-04 17:14 Dmitry Target Version => Icebox
2009-09-04 17:13 Dmitry Category Admin Interfaces => Data Management
2009-09-04 17:13 Dmitry Fixed in Version => Icebox
2009-09-04 17:13 Dmitry Summary Data validation engine redesign => Redesign "Data Dalidation" Engine
2009-09-04 17:13 Dmitry Description Updated bug_revision_view_page.php?rev_id=210#r210
2009-09-04 15:30 alex Relationship added related to 0000269
2009-09-04 15:30 alex Relationship added related to 0000270
2009-09-04 15:28 alex New Issue

Notes
(0003642)
alex   
2011-07-27 05:52   
(edited on: 2011-07-27 10:46)
Several problems found during implementation of this:
1. direct assignment of 'required' field option to unit config (from OnAfterConfigRead and it's hooks)
2. validation options must be stored in kDBItem class and then put into kValidator object for validation
3. in some places direct read of validation options occurs from field options array
4. formatters create virtual fields, like "CreatedOn_date" and copy required marks from Fields array into them. This way virtual fields, like 'CreatedOn_date' won't in validationOptions array to be properly validated


Due mentioned above problems I wasn't able to store validation options separately in kDBItem object and was force to merge them into kDBItem::Fields property during object initial configuration. Because of it it's impossible to change form name for already existing object.

However you can pass 'form_name' => 'form name here' in additional options during object configuration.

(0003755)
alex   
2011-09-17 05:07   
(edited on: 2011-09-28 12:11)
Affiliate processing changes TODO:
----------------------------------
1. make "affil.user" object load affiliate record associated with current logged-in record
2. use 2 prefixes on user registration form: "u.register" and "affil.register"
3. in UsersEventHandler::itemChanged check, that form_name is "form_registration" and then:
- recall affil.register object with skip_autoload
- set fields from request and call Validate
- if affiliate record not valid, then set $user->SetError on some fake user's field
4. in UsersEventHandler::afterItemChanged try to create affiliate object that was set before (and place user id insite it)

In forms, where affiliate record can be edited directly use "affil.user" without intermediate user object at all.

(0003935)
alex   
2011-09-29 10:43   
Done.
(0003936)
alex   
2011-09-29 10:44   
Will test later all together.
(0003937)
alex   
2011-09-29 10:46   
Fix committed to 5.2.x branch. Commit Message:

Fixes 0000271: Redesign "Data Validation" Engine
(0005006)
alex   
2012-07-25 05:32   
Since 5.2.0 version was released.