I am looking for help regarding how (and whether it is possible) to pass in an argument to the Views module which can update a field dynamically?
More specifically, I would like use a page like www.example.com/view/blue to pass in 'blue' and then select all users who have blue on a particular profile field.
Here's what I have now:
$view->filter = array (
array (
'tablename' => 'profile_companies',
'field' => 'value',
'operator' => 'contains',
'options' => '',
'value' => 'blue',
),
);
I'm wondering if there's some way to work with the Views module to change the hardcoded 'blue' to something like $arg[0] or %1, but I'm not sure if there's a way to do this directly from the module.
Thank you very much.
Comments
Comment #1
merlinofchaos commentedI believe you want to look in the Arguments section. I think there are arguments for the various profile fields.
Comment #2
youplatform commentedThanks Merlin, but I am still having difficulties. Can you clarify how (if there is a way) to pass in an argument and then refer to it in the "value" field of a filter. I know there is a way to do this in the title box (for example, %1 works when using taxonomy ID) but I have no idea (and can't find any documentation) on how to create a filter using the Views Module and then refer to an argument value for this.
Thank you very much.
Comment #3
merlinofchaos commentedYou can't refer to an argument in a filter; but you shouldn't have to. The arguments generally act as filters.
Comment #4
youplatform commentedHi Merlin,
Here's the scenario:
My user is a student looking to apply to school (say Stanford). He/she types in this university name in a free-form text field on the first page of the website and hits a submit button. I want to pass "stanford" as an argument to a launch a view of all other users on the site who have "stanford" in their university/college field that they filled out when they signed up.
Now I can set up a filter to do this for stanford or any number of other schools - I've been able to do this. The challenge I have is trying to allow users to type any school in and then do a query on that. Since I can't put an argument in the filter, I'm not sure how to go about doing this.
Is there a different module I should be using for this? I would have thought View would have this functionality built in, but I'm still pretty new on this site.
Thank you very much.
Comment #5
youplatform commentedStill unsure - would love to get someone's thoughts on this.
Thanks!
Comment #6
mooffie commentedYou can 'expose' a filter. Exposing a filter puts it on a form where the user can type values in.
In the settings page for the filter you'll see an 'Expose' button. Click it.
Comment #7
youplatform commentedExposing a filter helps for queries on that page. The question I have is how I can pass an argument to a filter from a prior page, via a URL? I'd like to continue to use the Views UI module to design views and load in an argument in the "value" field of the exposed filter.
My challenge is how I can best do this? I've tried using $arg[0], %1, but nothing seems to work.
I've come to think there is no way to do this so I wanted to check with the broader community, since Views seems like a pretty powerful/extensive module.
Comment #8
youplatform commentedI'm still working on this and would love some advice if anyone out there reads this and has used Views.
Thank you!
Comment #9
ghost4hire commentedI had the same issue of trying to pass a variable and I found a solution. I dont know enough PHP/SQL to tell you why this works, but it does.
Hopefully you can make your way thru this and find some useful information:
I needed to have multiple views in one node which took 3 different content types and sorted them by term. Basically its a mashup page of all the content types related to a taxonomy term, e.g. Blogs, Stories, Pages of Volkswagen>>Jettas
In my View, under Arguments I used these 3 arguments in this order (its important to order them correctly).
Argument Type>>Taxonomy:Term ID; Default>>Return Page Not Found;Title>>%1;Option>>0
Argument Type>>Node:Type; Default>>Display All Values
Argument Type>>Node:Feed Selector; Default>>Display All Values
I cloned the view and added filters as needed and used this http://drupal.org/node/212547 to then populate the views into one
I then needed to add a hardcoded link after each view which would send the user to only the content type view based on the taxonomy term, e.g. Blogs of Volkswagen>>Jettas.
I edited the PHP like this.
I dont know if this was the easiest/best way to do this, but it works for my purposes. Good luck and I hope this helps.
Comment #10
socialnicheguru commentedHi,
I am having problems with View Filter block
1. create a view with arguments
2. expose filters- these filters are not the same as the arguments passed in
if exposed filters is used, you get expected result
http://someurl.com/$arg/$arg/$arg
http://someurl.com/all/all/1?filter= ....
3. but when Views Filter Block is used the above URL becomes:
http://someurl.com/?filter=
with no arguments... HELP!
This is a major issue for me anyone else?
Chris
Comment #11
socialnicheguru commentedMy issue was with Views Filter Block
solution in views_filterblock.module
// Views filter block erases arguments
// change function
// http://drupal.org/node/112552#comment-796805
// Change action line
// http://drupal.org/node/112552#comment-823797
function views_filterblock($view) {
$action = (substr($_GET['q'], 0, strlen($view->url)) == $view->url) ? $_GET[q]\
: $view->url;
$form = views_filters($view);
$form['#action'] = url($action);
$form['#views_filterblock'] = true;
return $form;
}
Comment #12
cozzi commentedDid you ever figure this out?
Not that I need to do it now, but I just stumbled on this looking for a way to add a link as a view field (which I've not figured out yet) and your thread was very interesting. I can imagine many uses for it.
If you've figured this out please post what you learned.
Cheers!
Cozmo
Comment #13
kulfi commentedDesperately seeking argument handling help, but I don't have a (PHP) clue! The following is for filtering by taxonomy terms:
1. I'm using a simple HTML form to submit to a view, and the resulting URL looks like http://localhost/?q=my_view&color=1&color=3. What should my argument handling code look like so that it treats it the same as it would http://localhost/?q=my_view/1,3?
I've looked at http://drupal.org/node/70145 and http://drupal.org/node/54455, but I can't even get
print("Hello");to work from the argument handling section.2. I'd like to have a select field per vocabulary. Multiple values within a vocab are OR'ed. Multiple vocabs are AND'ed. e.g.
selecting Color: Blue, Green and Size: Small is treated as ((blue OR green) AND Small) or ((1 OR 3) AND 7) where Blue tid is 1, Green tid 3, Small tid is 7. Submitting to the view results in http://localhost/?q=my_view&color=1&color=3&size=7. Is it possible to create argument handling code to accomplish this?
Comment #14
manop commentedI solved my problem with this thread. http://drupal.org/node/344548
Comment #15
domesticat commentedClosed while closing all Views support requests with no activity for 6 months. If you still need help, you may re-open this issue at any time.
Comment #16
soumyadas commentedCreate a block view and change accordingly in the Arguments section.