Welcome Guest, Not a member yet? Register   Sign In
How to have 3 different searches use one controller
#1

[eluser]netenabled[/eluser]
Hi guys,

This is an architectural question about how I should set up my controller/views in order to reuse as much code as possible.

Currently I have a single controller called home.

In it I have a method "index" where I load the view for the homepage.

The homepage contains a search, which submits to a method in the home controller called "submit" which is used to validate the search forms entries.

If the validation fails it reloads the view and sends validation error messages to the view.

If successful, it loads a 2nd view the "results".

I now want to create a second/third/forth page containing the same search, that uses the same submission and validation as the homepage and then goes on to load the results view as above.

But I cant work out how I would achieve it?

The current search URL is www.example.com/

I want the second/third and forth to be www.example.com/thirdpage etc.

Can anyone help.

Many thanks

Scott
#2

[eluser]jairoh_[/eluser]
i did that in my last productions. i just made a header or nav that contains that search form and load it before my pages. Smile
#3

[eluser]netenabled[/eluser]
Hi Guys,

I still do not have a resolution to this.

I was moving forward by adding both the <set_value> and form_errors to Flashdata with a view to retrieve them on my redirect page.

For the most part this works! ie I can get individual error messages and fill in prefilled form inputs.

The issue I am now facing, is that I was also using <set_radio> and <set_select>

I am very new to coding and codeigniter. How could I pass these values too and have them set on my redirected page.

Any help would be greatly appreciated.

many thanks

Scott
#4

[eluser]Otemu[/eluser]
Hi,

The simple method is to have a search controller, then have the form action submit to this controller, whether you have the search on a 100 different pages there will all submit to the same controller, this controller will handle your validation and repopulate the form.

You could use Ajax to refresh the form view which will load all the search controller validation error messages, if validation is a success then redirect to the correct page, this way you stay on the original view and doesn't matter what page the search form was submitted from.

You could also as an alternative if it easier for you, just have a generic error page, if the form fails then this will redirect to that page and populate the form.

using <set_radio> and <set_select> examples below:

Example of using set radio here http://stackoverflow.com/questions/79829...adio-input

Example using set select here http://stackoverflow.com/questions/11876...pdown-menu

Hope that helps

#5

[eluser]netenabled[/eluser]
Hi thanks for the your update.

I ended up solving my problem by doing the following.

I save all individual error messages to flash data.

I also saved each individual post item.

Then on my redirect page I checked if an error existed in the flash and if so displayed it.

I also built the form to either select the value or add the value of the posts that were submitted.

Seems to be working a treat.

Thanks for your help

Scott




Theme © iAndrew 2016 - Forum software by © MyBB