Ask your Symfony questions! Pay money and get answers fast! (more info)

Error when submiting FormFilter Symfony

  • SOLVED

I get an error when submiting the FormFilter to filter values on a table. The FormFilter's code and the template code are provided bellow as well.

############
Error code:

500 | Internal Server Error | InvalidArgumentException
You must pass an array parameter to the clean() method

stack trace
at ()
in SF_ROOT_DIR/lib/vendor/symfony/lib/validator/sfValidatorSchemaFilter.class.php line 51 ...

if (!is_array($values))

{

throw new InvalidArgumentException('You must pass an array parameter to the clean() method');

}

$value = isset($values[$this->getOption('field')]) ? $values[$this->getOption('field')] : null;
at sfValidatorSchemaFilter->doClean('1')
in SF_ROOT_DIR/lib/vendor/symfony/lib/validator/sfValidatorSchema.class.php line 90 ...
at sfValidatorSchema->clean('1')
in SF_ROOT_DIR/lib/vendor/symfony/lib/validator/sfValidatorSchema.class.php line 157 ...
at sfValidatorSchema->doClean(array('regla_id' => '13', 'usuario_generacion_id' => '1', 'usuario_cierre_id' => '1', 'alumno_id' => '2', 'justified' => '', 'created_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2008'), 'to' => array('month' => '1', 'day' => '3', 'year' => '2010')), 'closed_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2009'), 'to' => array('month' => '3', 'day' => '3', 'year' => '2010'))))
in SF_ROOT_DIR/lib/vendor/symfony/lib/validator/sfValidatorSchema.class.php line 90 ...
at sfValidatorSchema->clean(array('regla_id' => '13', 'usuario_generacion_id' => '1', 'usuario_cierre_id' => '1', 'alumno_id' => '2', 'justified' => '', 'created_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2008'), 'to' => array('month' => '1', 'day' => '3', 'year' => '2010')), 'closed_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2009'), 'to' => array('month' => '3', 'day' => '3', 'year' => '2010'))))
in SF_ROOT_DIR/lib/vendor/symfony/lib/form/sfForm.class.php line 247 ...
at sfForm->doBind(array('regla_id' => '13', 'usuario_generacion_id' => '1', 'usuario_cierre_id' => '1', 'alumno_id' => '2', 'justified' => '', 'created_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2008'), 'to' => array('month' => '1', 'day' => '3', 'year' => '2010')), 'closed_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2009'), 'to' => array('month' => '3', 'day' => '3', 'year' => '2010'))))
in SF_ROOT_DIR/lib/vendor/symfony/lib/form/addon/sfFormSymfony.class.php line 75 ...
at sfFormSymfony->doBind(array('regla_id' => '13', 'usuario_generacion_id' => '1', 'usuario_cierre_id' => '1', 'alumno_id' => '2', 'justified' => '', 'created_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2008'), 'to' => array('month' => '1', 'day' => '3', 'year' => '2010')), 'closed_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2009'), 'to' => array('month' => '3', 'day' => '3', 'year' => '2010'))))
in SF_ROOT_DIR/lib/vendor/symfony/lib/form/sfForm.class.php line 227 ...
at sfForm->bind(array('regla_id' => '13', 'usuario_generacion_id' => '1', 'usuario_cierre_id' => '1', 'alumno_id' => '2', 'justified' => '', 'created_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2008'), 'to' => array('month' => '1', 'day' => '3', 'year' => '2010')), 'closed_at' => array('from' => array('month' => '1', 'day' => '1', 'year' => '2009'), 'to' => array('month' => '3', 'day' => '3', 'year' => '2010'))))
in SF_ROOT_DIR/apps/frontend/modules/alertas/actions/actions.class.php line 94 ...
at alertasActions->executeClosedAlerts(object('sfWebRequest'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/action/sfActions.class.php line 60 ...
##########

The FormFilter's code:

class AlertaFormFilter extends BaseAlertaFormFilter
{
public $fields = array('regla_id', 'usuario_cierre_id', 'justified', 'alumno_id', 'created_at','closed_at', 'usuario_generacion_id');

public function configure(){
$this->useFields($this->fields);

$this->getWidget('regla_id')->setOption('label', 'Regla disciplinaria');
$this->getWidget('justified')->setOption('label', 'Justificada');
$this->getWidget('created_at')->setOption('label', 'Fecha generación');
$this->setWidget('usuario_generacion_id', new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('sfGuardUser'), 'add_empty' => true)));
$this->setWidget('closed_at', new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)));

$this->getWidget('closed_at')->setOption('label', 'Fecha cierre');

$this->getWidget('created_at')->setOption('template', 'entre el %from_date% y el %to_date%');
$this->getWidget('closed_at')->setOption('template', 'entre el %from_date% y el %to_date%');
}
}

The template's code:

<form action="<?php echo url_for('alertas/closedAlerts') ?>" method="post" id="<?php echo $formFilter->getName() ?>">
<div><?php echo $formFilter ?></div>
<input type="submit" value="Filtrar"/>
</form>

This error occurs both when I fill out all the filtering fields, and when I don't. Any help would be appreciated.

Answers (2)

2011-05-27

José Nahuel Cuesta Luengo answers:

You're having troubles with your validators/widgets configuration. Check your BaseAlertaFormFilter class for fields whose widget you have customized that are using a sfValidatorSchemaFilter. The error is that you are sending a non-array value to a validator that expects an array value to clean.

It's most likely you have changed a sfWidgetFormFilterInput -which returns an array of 2 values- with another widget that just returns a value in a data type different from an array.

Maybe 'usuario_generacion_id'?

2011-05-27

Loban Rahman answers:

You have specifically set an sfWidget for each of <em>usuario_generacion_id</em> and <em>closed_at</em>, but have not specifically set a corresponding sfValidator for each of those two fields. Probably the original validators of those two fields (check the BaseAlertaFormFilter) is not compatible with the widgets you've choices.