You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly.

Hiding Views Output Until User Input

 

If you've ever used the drupal views module, chances are at some point you've needed to suppress any output until AFTER the user has made a selection from one of your exposed filters.  Views actually DOES make this possible, but it's not exactly self-evident.  I'm going to run you through a quick "howto" on this as I'm sure many people have needed it at some point.

As I mentioned above, this is possible but not particularly self-evident.  Views has a number of different "global" group items.  The most common of these is probably the Random Sort.  Within arguments you also have another member of the global group, the global NULL argument.  This is basically a way of attaching your own rudimentary argument to a view.  Through the use of the default value (as custom php) and custom validation (again through php) you could cook up just about anything.

With our global NULL argument in place, the following settings are about all we need to make this really work:

1.) Provide a default argument
2.) Argument type -> Fixed entry (Leave the default argument field blank as what gets passed is irrelevant to our needs, we simply needed to make it to the next level which is validation
3.) Choose php code as your validator
4.) Check through the $view->exposed_input array.  I recommend using devel module's dsm() function here because it will respond on the ajax that view is using (unlike drupal_set_message()).
5.) Set "Action to take if argument does not validate:" to "Display empty text"

You can get as fancy in step 4 as you need, but it's just down to good old php if statements at that point.

I hope this howto helps other people.  We've found it rather useful, and since it's sort of arcane, I wanted to share it.

Thanks to Earl Miles (merlinofchaos) for pointing me in the right direction on this one!

 
The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • HTML tags will be transformed to conform to HTML standards.

More information about formatting options

 

Great solution

I have tried to solve this problem for a while in my sites, great solution

UG

dsm() and drupal_set_message()

This is a really minor point, but don't dsm(), dpm(), and dvm() use drupal_set_message() internally? They should all display just fine. Of course, we should still recommend one of Devel's functions just so you can see the entire array structure more easily.

Yeah, so...

You'd think that.  I don't know what makes the difference, but I've never had drupal_set_message actually work on the ajax calls the way dsm does, so I'm not sure of the specifics, but bottom line, drupal_set_message() doesn't work for this particular application. <shrug />

Nevermind

I seem to be wrong.  Playing with it earlier today, drupal_set_message() does seem to work, but dsm is a better solution.

Little Clarification

I'm able to follow everything except for number 4. I do not really understand what I'm supposed to check for and what I'm supposed to do if I find it.

"4. Check through the $view->exposed_input array."

Thanks for the help.

Tim

@Tim

The devel module provides a number of different developer tools, amongst them is the dsm() function.  You can simply just dsm($view->exposed_input) from within the custom php validation on the views argument, and that will print out the current value of all your exposed filters.  You can then write a little code to check these values, and if they're empty/NULL/whatever simply return FALSE.

I hope this makes it a bit more obvious what I'm trying to illustrate here.  I also hope to respond to this in a video response, but we'll see how far I make it.

re:

Through the use of the default value (as custom php) and custom validation, I was able to address a few of the issues we have.

Thanks, vivetra.

This solution is really

This solution is really working great for me. Sometimes its really needed to suppress your output until the user made any selection. At such situations this module provides us that facility. Thanks.Motorcycle personal injury attorney

Wow. i am so happy i found

Wow. i am so happy i found this site. I am really confused about how that works, thank you so much for sharing this. I am looking forward to read more of your articles. Keep up the good work.

A very informative site with

A very informative site with a wide range of interesting perspectives. I'll certainly continue to visit it. Well done!