Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Force validation rule to run with empty fields in data set
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Gaiser  
View profile  
 More options Jun 8 2012, 4:13 am
From: Michael Gaiser <mjgai...@gmail.com>
Date: Fri, 8 Jun 2012 04:13:31 -0400
Local: Fri, Jun 8 2012 4:13 am
Subject: Force validation rule to run with empty fields in data set

So I need to check that at least one field out of four is being set before
I will allow to save. The validation rule works great as long as you have
something sent to it, but since all the option fields have an empty slot,
it would be easy to pass an array with all the right bits of info for that
table except for one of the four ids. Since none of the four had data sent
to them, their validation rule never gets called and it allows it to save.
Any ideas how to get around this? I have tried to play around with the
'required' flag, but it really doesn't seem to be what I am really looking
for since it would require all four to be set before allowing it to save.
Any ideas? Thanks in advance.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
veganista  
View profile  
 More options Jun 8 2012, 4:19 pm
From: veganista <l...@nanothree.net>
Date: Fri, 8 Jun 2012 13:19:03 -0700 (PDT)
Local: Fri, Jun 8 2012 4:19 pm
Subject: Re: Force validation rule to run with empty fields in data set

I have done this before in (1.3) but it wasn't a pretty solution.

If your using 2.2 you might want to take a look at this:
http://book.cakephp.org/2.0/en/models/data-validation.html#dynamicall...

You could use that in the beforeValidate() callback of the model and choose
what validation rules to add based on the data supplied.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Gaiser  
View profile  
 More options Jun 8 2012, 4:58 pm
From: Michael Gaiser <mjgai...@gmail.com>
Date: Fri, 8 Jun 2012 16:58:23 -0400
Local: Fri, Jun 8 2012 4:58 pm
Subject: Re: Force validation rule to run with empty fields in data set

I have added the validation rule already to the model and it works when
there is data supplied to it, but I still need a way to force it to run the
rule even if $this->request->data is empty when saving. I need to be able
to tell it to run the rule because even if that field is empty, there might
be another one that has the data. How do you get a rule to run even if the
field its attached to doesnt have any data? How do you detect that out of
the 4 possible links, none were selected to be saved?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Liam Linacre  
View profile  
 More options Jun 8 2012, 5:05 pm
From: Liam Linacre <l...@nanothree.net>
Date: Fri, 8 Jun 2012 23:05:50 +0200
Local: Fri, Jun 8 2012 5:05 pm
Subject: Re: Force validation rule to run with empty fields in data set

I'm pretty sure i know what you are trying to do (in my application an
address model requires one of: flat_number, house_number or house_name).

In your before filter you can add and remove the validation rules based on
what data is available. Can you do a var_dump() of $this->request->data
that'll help me show you what i mean.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Gaiser  
View profile  
 More options Jun 8 2012, 5:27 pm
From: Michael Gaiser <mjgai...@gmail.com>
Date: Fri, 8 Jun 2012 17:27:21 -0400
Local: Fri, Jun 8 2012 5:27 pm
Subject: Re: Force validation rule to run with empty fields in data set

Its not in front of me at the moment, but I can mock up what I mean.

array(
  'Domain' => array(
    'name' => 'Foo',
    'parent_id' => '85'
  ),
  'Owner' => array(
    'color' => '#123456',
    'clan_id' => '32'
  )
)
This would be valid since clan_id (character_id, coterie_id & covenant_id
being the other valid choices) is set. My code handles this properly.

array(
  'Domain' => array(
    'name' => 'Foo',
    'parent_id' => '85'
  ),
  'Owner' => array(
    'color' => '#123456',
    'clan_id' => '32',
    'character_id' => '71'
  )
)
This would fail because the Owner object has both a character and a clan
assigned to it and it can only have one for my purposes. My code also
handles this situation properly.

array(
  'Domain' => array(
    'name' => 'Foo',
    'parent_id' => '85'
  ),
  'Owner' => array(
    'color' => '#123456'
  )
)
This should fail because I need atleast one of the four link id's to be
present, but because none of the 4 field id's isn't present in the dataset,
the rule isn't run. Normally you would just tell the field that its
required which would force it to throw an error if its empty, but being
empty isnt an issue if one of the other fields has data.

I can add and subtract rules from what I read in that docs, but they still
will not run if there isnt any data to trigger them.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »