Hello.

During the last few days I have made some modifications to the
validation process.
The problem I tried to solve was in my case as follow:
In a form I displayed the values of entries from other tables where
the main table had FKs.
I had 12 FKs pointing to an other table like this:
water_jan,
water_feb,
....
water_dec
This could be handled by the validation framework as it is now but I
had to enter
24 validation(2  for each fk) rules and this was boring.

The form displays also, fields from other tables which have FK to the
main table.
The structure of those field names is table_name$counter{field_name}.
For this fields I could not write a validation rule since there is no
a priori knowledge
of the number of the records pointing to the main table (the max value
of counter).

In order to solve this shortcomings I did this:
a)Defined a new attribute in the rules specification named
parent_pattern
The attribute will store a regular expression which matches the parent
of the field.
For example:
   water_presence_spatial:
    parent_pattern: water_(jan|feb)
    required: Yes
      msg: Water for month /1uaray is not provided
    w_spatial:
This means that the rule will apply to fields named
water_jan{water_presence_spatial}
or
water_feb{water_presence_spatial}
In the error message the /1 will be replaced with jan or feb
An other example illustrating the second case:
  code:
    parent_pattern: hab_code(\d+)
    stringValidator:
will match fields hab_code\d+{code}

This was the idea.

The implementation is based on the fact that the generated
file:modules_ModuleName_validate_*.yml.php
has access to the request object.
I modified the sfValidatorConfigHandler in order to do this:
if the field has defined the parent_pattern attribute generate the
extra code

if the request has a field which it's name matches the
parent_pattern[field_name] then
register the field for validation
register the validators of this field
where the parent will be what the parent_pattern matched


I'm sending this message for feedback on the idea of handling the two
cases above.
The code is still premature for publication.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to