Hey there everyone, I've got yet another question that has me stumped currently...
What I'm working on seems insanely easy to me, and it's almost as if the damn thing should be really easy to pull off, but I can't quite figure it out! Anyways, I am using the date module, and have a start date and a to date, or year specifically. All that hoorah is correct so don't worry about it. I have a view which you can pass a year argument, and it will only show nodes that have that year inbetween the initial and final year. 100% basic, 100% works fine. Type in a year and it chugs out the nodules of relevance just like it should.
So here's the question that seems so basic yet I don't know how to answer:
How do I get the year from the user (form perhaps?), and then pass it to the views module? Basically, I want to make a search like function, only it simply asks the user for year. In the future it would be cool to allow the user to search for topics along with year of relevance.
Anyways, any help would be appreciated!
Thanks,
Jesse

Comments
use drupal_goto()
If you use a form, then in the submission handler you could use drupal_goto().
So for example, if the path to your views page is 'calendar', then something like this in the form submission handler:
$year = $form_state['values']['year'];
drupal_goto('/calendar/'.$year);
See http://api.drupal.org/api/function/drupal_goto/6
Thanks for your help! Just
Thanks for your help!
Just last night I got around to sorting everything out and figuring out how it worked. It was rather confusing as I had no clue how to build forms, or where I even would build a form at all... but I finally found a basic walk through that told you how to create your own module with a form, and then a ton of different form examples. I then just used dropal goto like you suggested, and even wrote in an if/else to handle if the topic field was empty or not. It works great. The ability to create these and work them with views arguments will really enable me to do some cool things.
The dude responsible for -- Mt Hood Snow Sports --
Jesse Nicola -- Shredical six different ways to Sunday! -- My Portfolio
Final Solution Writeup?
Hey, congrats on getting it to work. Would you consider writing up how you got to your final solution? I'm curious on how exactly you accomplished this and which which modules were used in the end.
Cheers,
The solution to creating
The solution to creating forms in drupal that redirect and include the form data in the address:
I encountered a situation where I desired to create a form that users would fill out, and then instead of storing the information somewhere in the database, I simply wanted to pass on the user entered information to views. This would create search like functionality for views.
The problem then was, I didn't know where I was even supposed create a form! Do I do it in the text of a "page" content type as PHP, or do I... alright the whole process lost me. No modules exist that I could find which enable the creation and handling of forms. Also, the problem with using HTML forms, is that the data when submitted uses a "?" to seperate the information, which doesn't play well with drupal clean urls.
The solution I found was HERE, or at least partly. This is a 10 step tutorial showing you how to create your own module, which takes the shape of a form on the user end of things. This will be immensly helpful to those who didn't even know that forms had to take shape inside of modules. It teaches you how to work with drupals form API and create forms. It doesn't quite explain how to go about storing the information, but that would of course require some mysql knowledge, and a lot of knowledge about how drupal structures all of it's data... or at least I imagine.
The next step was finding in the tutorial's module where the form is submitted, and adjusting what the form does. This is the area of importance in the code for their module:
function my_module_my_form_submit($form, &$form_state) {drupal_set_message(t('The form has been submitted.'));
}
The above code simply displays a message that the form submitted. That is nice and all, but hardly what we're looking for as a result! I then took the code DRM showed me earlier in this discussion and replaced the drupal_set_message above with his code:
$year = $form_state['values']['year'];drupal_goto('/calendar/'.$year);
Bear in mind 'year' was a user submitted text field in the form. If you don't understand what that means or where it is found, review the 10 step tutorial and you'll understand. So this worked in passing the 'year' value to the view as an argument. Then I decided to get tricky, and not only allow for one argument, but allow for a second OPTIONAL argument as well. My form submit function looks like this:
function searchbydate_search_form_submit($form, &$form_state) {
$year = $form_state['values']['year'];
$topic = $form_state['values']['topic'];
if (empty($topic))
{
drupal_goto('bydate/'.$year);
}
else
{
drupal_goto('bydate/'.$year.'/'.$topic);
}
}
Bear in mind when reviewing the above code, that I renamed all of the fields from being "My_form" to "searchbydate", and my view wasn't located at "calendar" it was located at "bydate". The if/else I wrote checks to see if the topic field is empty. If the topic field is empty, then it only passes the first argument. However, if it is not empty (else), it passes both onward to the view.
That's how it went, and after tons of chasing my tail around I managed to dig up the tutorial, and do exactly what I needed! WORD UP!
The dude responsible for -- Mt Hood Snow Sports --
Jesse Nicola -- Shredical six different ways to Sunday! -- My Portfolio
exposed filters
Glad you got it to work. I think I would use views "exposed filters".
If you need the form displayed on a different page, you can always just grab the form with something like this:
http://www.computerminds.co.uk/displaying-exposed-filter-form-views-drup...
(You used to just be able to use drupal_get_form(), but that doesn't work quite the same in Views 2).
Thanks
Awesome description of your solution, thanks! Helps to better understand the process. The exposed filters method also seems like it will be handy
Thanks!