Illegal choice error in Views exposed filter of user reference field using a view of Organic Groups group members


By Aaron - Posted on 15 February 2010

Wow, how is that headline for a bunch of Drupal gobbledygook jargon?

To break it down, I have a content type with a cck user reference field.

That field's options are populated by the results of a view.

That view builds a list of users who belong to the same Organic group as the active user. It has a argument that supplies the user's group by default. That works fine because users can only belong to one group on this site.

But anonymous users don't belong to groups, so no results are returned.

Then I have view that displays results of the content type. It has an exposed filter for the user reference field.

It didn't occur to me that the exposed user reference options were also coming from the same view that populated the user reference options in the content type form. I incorrectly assumed they would come from the stored values from that field in the database.

So, when an anonymous user tried to see the results view with the exposed filter, the choices in the filter where empty, and if I fed the anon user a path as if he had selected a choice in the filter, he got the illegal choice because that choice didn't exist.

So the solution is to anticipate who ALL users of the user reference field might be, not just the ones who are creating the content in the node add form.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor.
Fill in the blank