1. CGI with hyperlink
- Posted by Jerome Dec 26, 2010
- 1582 views
I am currently using Euphoria, mysql, and CGI to access my cooking recipe database online. I have a simple form where a user can search recipes by different criteria, and the EU code returns an HTML page with the results. What I would like is for the results to have the ingredients as hyperlinks, so when clicked can search the database for other recipes with that ingredient. An example result would be:
Recipe Name | Katsu Pork |
Ingredient | Pork |
Ingredient | Rice |
Can I setup another form that uses the hyperlinks somehow as the post criteria? Or is there another method?
Happy Holidays!
- Ira
2. Re: CGI with hyperlink
- Posted by jimcbrown (admin) Dec 26, 2010
- 1707 views
I am currently using Euphoria, mysql, and CGI to access my cooking recipe database online. I have a simple form where a user can search recipes by different criteria, and the EU code returns an HTML page with the results. What I would like is for the results to have the ingredients as hyperlinks, so when clicked can search the database for other recipes with that ingredient. An example result would be:
Recipe Name | Katsu Pork |
Ingredient | Pork |
Ingredient | Rice |
Can I setup another form that uses the hyperlinks somehow as the post criteria? Or is there another method?
Happy Holidays!
- Ira
The nicest way is just to modify your CGI to be able to accept HTTP GET as well as HTTP POST, and then the hyperlink would just go to "/cgi.ex?search=Pork"
Alternatively, you can use javascript to create a hyperlink that can send a true HTTP POST request.
See http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-data-between-pages/
3. Re: CGI with hyperlink
- Posted by Jerome Dec 26, 2010
- 1585 views
Thanks for the help! I'll setup my CGI to accept both HTTP GET and POST, which should work nicely!
- Ira
4. Re: CGI with hyperlink
- Posted by dukester Dec 26, 2010
- 1587 views
[snip]
Can I setup another form that uses the hyperlinks somehow as the post criteria? Or is there another method?
You bet!
When you use the GET method, data is sent via the QUERY_STRING environment variable. When you use the POST method, the data is sent vis STDIN. Either way, the data is "packaged" the same way, i.e. it has to be encoded. For example the QUERY_STRING might contain:
star=Eastwood&cert=15&movie=Pale+Rider
each variable=value pair is separated by a "&"
spaces are replaced with a "+"
certain characters are replaced with their hex values like %xx
So, to send send the data via a link on your webpage, encode it (as shown above) and append it to your URL, like:
<a href="http://www.hotchef.com/cgi-bin/my-script.cgi?star=Eastwood&cert=15&movie=Pale+Rider">Chef's Movie of the week</a>
Actually, the above link is the very same data that would be sent to the server (and that would appear in your browser's navigation window) using a web form.
HTH ...
Duke
5. Re: CGI with hyperlink
- Posted by Jerome Dec 27, 2010
- 1446 views
Duke,
Thanks again! I now check the Request_Method environment variable for either the POST or GET Method. I then just break apart about the encoded data accordingly. My recipe database is now fully functional!
- Ira
6. Re: CGI with hyperlink
- Posted by dukester Dec 27, 2010
- 1467 views
Thanks again! I now check the Request_Method environment variable for either the POST or GET Method. I then just break apart about the encoded data accordingly. My recipe database is now fully functional!
Super! have fun ...
and Happy New Year! - in the kitchen as well! :)
Duke