Ciao Richtermeister,
I wrote the validator as a Callback:
<?php
/**
* Listino form.
*
* @package SuperAdmin
* @subpackage form
* @author Your name here
* @version SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21
07:10:32Z dwhittle $
*/
class ListinoForm extends BaseListinoForm
{
public function configure()
{
$this->widgetSchema['DataInizioValidita'] = new sfWidgetFormI18nDate
(array('culture' => 'it_IT', 'month_format' => 'short_name'));
$this->validatorSchema->setPostValidator(new sfValidatorCallback
(array('callback' => array($this, 'checkSoglie'))));
}
public function checkSoglie($validator, $values)
{
$trovataSoglia = false;
<snip>
if ($values['Importo'.$i] >= $values['Importo'.($i - 1)])
{
throw new sfValidatorError($validator, "Ogni importo deve
essere inferiore al precedente. (Importo$i)");
return $values;
}
}
return $values;
}
}
and I put it in lib/form/<model>Form.class.php.
It's form and problem specific, so I'm not going to reuse the logic
anywhere in the project.
I wonder if this is the right place where to put the code!?
Now I'm looking for a way to highlight the wrong fields (with a red
border, like the standard validators do) to the user...
Stefano
On 12 Ago, 20:34, Richtermeister <[email protected]> wrote:
> Hey Stefano,
>
> I would write a custom post-validator. A post validator is given the
> entire data array, so from there you can just loop over the array and
> see if the values keep increasing..
>
> Hope this helps,
> Daniel
>
> On Aug 12, 8:57 am, Stefano <[email protected]> wrote:
>
> > Hi,
>
> > I'm developing my first web-application and I'm still RTFM (Reading
> > The Fabulous Manuals), but I need a little help with a form
> > validation.
>
> > For this application I'm using the Admin Generator.
>
> > The form contains 5 target fields: T1, T2, T3, T4, T5; every target
> > must be greater than the previous: T1 < T2 < T3 < T4 < T5.
>
> > But only T1 is required while the other targets can be empty.
>
> > If a target is empty all the next ones must be empty.
>
> > So:
> > T1= 100, T2= 200, T3=empty, T4=empty, T5=empty is valid,
> > but:
> > T1=100, T2=empty, T3=200, T4=empty, T5=empty is NOT valid.
>
> > I'm putting some code in lib/form/<model>Form.class.php:
>
> > class ListinoForm extends BaseListinoForm
> > {
> > public function configure()
> > {
> > $this->validatorSchema->setPostValidator(new sfValidatorAnd(array
> > (new sfValidatorSchemaCompare('T1',
> > sfValidatorSchemaCompare::LESS_THAN, 'T2'))));
> > }
>
> > }
>
> > but I don't know how to test if a field is empty and I'm afraid that
> > the resulting instruction will be very hard to read.
>
> > Any hint?
>
> > TIA
>
> > Stefano
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---