Have you remember to include the _csrf_token hidden field in your ajax
request? If you are serializing the entire form for send that shouldn't be
an issue but if your ajax is serliazing each field one by one just check to
make sure you are including the field _csrf_token

2010/11/17 Philipp Schächtele <[email protected]>

> Dear Symfony Users,
> I have a odd problem with the sfValidatorChoice and AJAX and need your
> support. The validator (with 'multiple' => true) works fine when I
> test my form via a normal submit (using the input-submit button), but
> returns "invalid" when I test it with multiple selected values online
> with AJAX (ajax request is sent to a route which returns only the html-
> form without the layout which replaces the form on the page) -
> although the input is actually valid.
>
> This is my form configuration:
>
> // The options for the select box
> $catalog_article_group_options = array(
>  'frames' => 'Frames',
>  'sunglasses' => 'Sunglasses'
> );
>
> $this->widgetSchema['catalog_products'] = new sfWidgetFormChoice(
>  array(
>    'choices' => $catalog_article_group_options,
>    'multiple' => true
>  )
> );
>
> $this->validatorSchema['catalog_products'] = new sfValidatorChoice(
>  array(
>    'multiple' => true,
>    'min' => 1,
>    'max' => 6,
>    'choices' => array_keys($catalog_article_group_options)
>  ),
>  array(
>    'required' => 'Please select at least one article group.',
>    'min'     => 'Pease select at least one article group.'
> ));
>
> The setup is clear: The user should select at least one article group
> form a Select-Element, but can select more if he or her wants to.
> Testing this form via normal submit in my development environment
> shows correct behaivor. If one or more values are selected, the input
> is valid.
>
> When I use the form via AJAX the behaivor is different: When I select
> no value I receive the "min" validation message, which is correct.
> Same with one value selected, which returns valid. So far, so good.
>
> Now it comes to the error:
> When selecting more then one value and validate this request this
> returns a validation message "invalid". When I compare the POST-
> requests of the normal form-submit and the ajax request they are the
> same ( decoded it says ...&lead[catalog_article_group]
> []=frames&lead[catalog_article_group][]=sunglasses&...), even the
> content-type is identical (application/x-www-form-urlencoded). So the
> request looks fine to me but symfony behaves differently. How come?
>
> Has anybody experienced a similar error?
> Might the reason lie in AJAX (although the request seems to be the
> same)?
> Are there problems with my configuration (but why does it work locally
> then)?
>
> Thanks for you help and hints in advance!
>
> Kind regards,
> Philipp
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> 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]<symfony-users%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>



-- 
Gareth McCumskey
http://garethmccumskey.blogspot.com
twitter: @garethmcc

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

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

Reply via email to