It's my first post And i m happy to say HI

How to pass an argument from form (like search) to my views ?

i have create views with filter and arguement and i have my path url in views like that : mytaxonomy/%

so , my url : www.exemple.com/drupal/mytaxonomy/1050 works fine . but i'd like to creat a form like seach to pass an argument to this views

thinks

Comments

tommytom’s picture

does anybody know the answer ?

sattyani’s picture

I am working on a similar scenario, I need to create a search form then pass the arguments to the view. Let me know if you find an answer

Thanks
Samir

petebarnett’s picture

You can build a form that has $form['#action'] set to the URL of your view.

You'd then need to add an argument to your view, ticking "Exclude the argument" at the bottom. This exists so that views absorbs the argument being passed in, which could be something like "?area=Scotland", and wouldn't make sense to views directly.

We then add a second argument, and set "Action to take if argument is not present" to "Provide Default Argument". Select type "PHP Code". This is where we use php to process the result of the form, and return a value that makes sense to views... Basically use php to return what you want, for example: return $_GET['term_id']

Hope this helps.

Peter

sattyani’s picture

It helps a lot, I am still new to Drupal and need to find my way how to create a form, setup argument, etc.. but this is a great start.

by the way, what is the best way to build a form that has $form['#action'] in drupal?
Samir

sattyani’s picture

Please help on this, I am really not sure if there is a module I can use or if I need to create a custom module or just pure php page to build the form. I then need to pass these values to the view so only matching records are shown.

I am very new and just not sure what to look for

Samir