Skip Navigation

[Resolved] Use one Front Page Form To Set Post Type and Location For Distance Radius On Ind

This support ticket is created 3 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Don 3 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#2076333

Don

Tell us what you are trying to do?

I would like to offer the same functionality that is pretty much standard in my niche, and have a simple form on the front page that sends a user to 1 of 3 pages (I only have 3 post types) but also with the "location" to be used for the "distance" from the address field value also already set when they land on the view page for that post type.

so basically a simple one line form with a dropdown to select the "Category"(post type) and a autocomplete address field and submit button. Upon submit they go to the page /mysite/posttype1(or 2 or 3) with the address to use for distance radius already defined.

Is that easy enough to do? I would really like to combine them like is typical on sites in my area, rather than "only" offering the categories/post types, and then on that site having to define the WHERE.... I just wasnt sure if possible since the form redirects to one of three different views, and whether can send the address to filter distance by as well....

#2076543

Hi, it sounds like you want to display a custom search form with an address input, some type of select filter, and a submit button, and display that on the home page. When the User submits that custom search form, you want to redirect them to another page, one of 3 possible options, based on the post type selected in the filter. Those landing pages also have their own custom search Views with address filters, and you want to carry over the address field entry from the home page form submission into the address field in the landing page search form.

The short answer is Views does not provide everything you are looking for here out-of-the-box, and some custom code is necessary to achieve it exactly like you've described. It is possible to create custom search Views with filters, display filters alone on one page, and redirect the User to another page containing similar filters and results, and pass the selected options from the initial search into the new page's search filters. That's definitely possible, and is in fact how the Views system is designed to work. You can create two custom search Views that both include an address filter. On the home page, you would display the filters of View #1 only, and you would configure that search View to display the results on another page with a redirect. You would place both the filters and results of View #2 on that destination page, and the address submitted on the first page would automatically be carried over into the address field in the second page, where the results would also be displayed. Depending on how you want to set up the second custom search View, you could include other filters as well as the address filter. It is possible to set up something similar now using Views created in Blocks, but one of your requirements is not so easily solved.

You would like the redirect destination from the homepage search form to be variable based on the selection in one of the filters. Views does not provide this variable redirection capability. The redirect destination is set when you insert the filters for View #1 as I described above. The destination is static, not variable based on filter selections. You will basically choose one page as the destination for the redirect, and the search form will always redirect to the same destination regardless of filter choices. So that is the main problem you would need to overcome here, and there is no simple solution. Our Views APIs do not provide a simple way to programmatically change the destination of a search redirect in this scenario. I think a custom JavaScript solution would be necessary. You would need to set up an event handler that listens for changes in the "category" or "post type" filter you mentioned, and triggers an update in the form tag's "action" attribute. That would programmatically adjust the destination URL for search form submissions on-the-fly as the User changes the filter trigger. This type of customization falls outside the scope of the support we offer here in the forums, but there are similar code examples online which you could use for inspiration to create your own custom solution.
I searched for "javascript change form destination based on selection" and found:
https://stackoverflow.com/questions/25960729/change-form-action-on-select-option/25960880

Also you mentioned "category" and "post type" when describing this filter, so I'm not quite clear what type of filter this really needs to be. Views does offer taxonomy filters, but does not offer post type filters. So if this is really a post type filter and not a taxonomy filter, you may need to create a custom select field using HTML instead of relying on the Views system to create and display one for you, since post type filters are not available.

Let me know your thoughts and we can continue our discussion.

#2077071

Don

thank you so much for the thorough and thoughtful assistance and suggestions. Based on your clarifications, I have decided to, hopefully, make the process more simple:

1) first off, to clarify any confusion, I was using the "category" and "post type" basically interchangeable since in toolset they are officially post types but, for my needs and as they will be viewed on the front end by users, they are the equivalent of "categories".... but i realize that is not doing the range of what post types can be justice.
2) To simplify things I have decided to remove the whole issue of having to determine the post type and "where to" (ie which page with its relevant view) by using TABS on the front page..... then in each individual tab, the only "field" is a autocomplete text box, and a submit button that, when clicked, will go to the correct page (with a post type view on it) and the distance radius location info with it.

I really appreciate you taking the time to clarify what is and isnt possible, saved me a LOT of time looking for a way to do it one way, which would have been incredibly difficult, instead of settling on a slightly different "layout" that made things a whole lot easier. is only a bummer that, since it looks like i have to do it as custom html, it isnt near as easy and elegant to style as if it was done with toolset fields etc..... but main thing it works!

#2077745

Don

My issue is resolved now. Thank you!