开发者

Implementing Form that Might Result in Different Queries

开发者 https://www.devze.com 2023-02-08 09:22 出处:网络
I have a form that needs to allow people to search for hikes, hiking groups, or hikers, depending on what radio button they choose within the form.

I have a form that needs to allow people to search for hikes, hiking groups, or hikers, depending on what radio button they choose within the form.

Obviously, in either of these 3 cases, the query will be of different tables in the database, and have different usability down the road. So I probably shouldn't process all of these in one place I am assuming. Would you guys agree?

What might be a good开发者_JAVA技巧 practice way to handle such a case? I tried redirecting the request to single form processing modules, but I had trouble making a POST request in the URL that I was trying to redirect.

Ideas/suggestions appreciated, Alex


I don't see a problem handling this from 1 form. pass on the search type and build an appropriate query based on the type, search terms, etc. Even if the queries are totally different, it sounds like the input your gathering is pretty simple. You may want to display the results with different pages, but processing can easily be handled with one form and one script.

Quick example:

//get variables out of POST

if ($search_type == "hike")
{
    //put together a hike query, get results
    //call script to display hikes
}
elseif ($search_type == "group")
{
    //put together a group query, get results
    //call script to display hikes
}
elseif(...) //etc, etc


You can just check the value for the radio button and call different methods for further handling the form. That way you can put the queries and any related code in totally different files. Where exactly do you see a problem in that? In how is the handling behind the screens related to user-experience?

0

精彩评论

暂无评论...
验证码 换一张
取 消