CodeIgniter Forums
How to Convert Form Get Method (Query String) URI into Segment URI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to Convert Form Get Method (Query String) URI into Segment URI (/showthread.php?tid=55823)



How to Convert Form Get Method (Query String) URI into Segment URI - El Forum - 11-11-2012

[eluser]andrew nevins[/eluser]
Hi all,

I've been searching for a while on Google, but have only found how to enable Query Strings http://www.askaboutphp.com/58/codeigniter-mixing-segment-based-url-with-querystrings.html .

I have a form that uses a GET method and produces this URI,
Code:
books/course?course_id=CC100&format=XML&submit=Submit

I want to convert this URI to use Segments, just as a POST method would produce.
The ideal URI I would like is:
Code:
books/course/CC100/XML

Anyone know how I'd go about this?



How to Convert Form Get Method (Query String) URI into Segment URI - El Forum - 11-11-2012

[eluser]jprateragg[/eluser]
Any particular reason why you would want to do this?

I'm still fairly new to CI, but you could have two functions in your Books controller--one that hosts the form, and another that displays the results using a redirect. You could have your form controller display the form submitting it via post, format the output to a segmented URI, then redirect to a second controller that just shows the results.


How to Convert Form Get Method (Query String) URI into Segment URI - El Forum - 11-12-2012

[eluser]andrew nevins[/eluser]
The reason why I must use a GET method is it's part of the brief.
Quote:"Three main HTTP GET requests are required to be implemented. Each should be implemented as JSON and XML according to the URL of the request :-

A. Books by course

http://www.cems.uwe.ac.uk/~<yourusername>/atwd/books/course/<course-id>/xml
http://www.cems.uwe.ac.uk/~<yourusername>/atwd/books/course/<course-id>/json"
I'm using a post method for another form and it generates the correct URI structure, it's just a problem I'm experiencing with a GET method.


How to Convert Form Get Method (Query String) URI into Segment URI - El Forum - 11-12-2012

[eluser]Aken[/eluser]
In my knowledge, there's two options: 1) change the action URL via Javascript 2) use an intermediary controller to process the GET request and redirect appropriately. Perhaps someone else has another solution that I'm unaware of.