PHP navigation question: POST and hyperlinks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sapphon
Forum Newbie
Posts: 4
Joined: Sun Jan 03, 2010 6:32 pm

PHP navigation question: POST and hyperlinks

Post by Sapphon »

Hello all,

Very new to web programming; thanks in advance for your patience.

The application I'm developing is not a dictionary, but it's close enough to be a useful parallel. Suppose a user has just done a search for words and found that 5 words in the dictionary match her criteria.

Now, what I've made happen is that each of those 5 words is displayed on the screen as a hyperlink that leads to a page with complete information on that word using false GET variables to tell the destination page which word to take information from the database about (for example, findwords.php returns 5 links; links go to viewword.php customized for the particular word clicked; viewword.php has one link that goes to editword.php with the form prefilled with the data for that same word).

My question is, is this the usual/best way of doing things? Is there some other method of dynamic navigation that will allow me to use POST instead of encoding the information in the URL with GET? I'd much prefer it if there were.

Thanks very much!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP navigation question: POST and hyperlinks

Post by requinix »

Don't know what you mean by "false GET variables", but yeah, sure, you can use forms.

If the buttons are the words themselves then it's really easy:

Code: Select all

<form action="viewword.php" method="post">
<ul>
    <li><input type="submit" name="word" value="their" /></li>
    <li><input type="submit" name="word" value="there" /></li>
    <li><input type="submit" name="word" value="they're" /></li>
</ul>
</form>
Sapphon
Forum Newbie
Posts: 4
Joined: Sun Jan 03, 2010 6:32 pm

Re: PHP navigation question: POST and hyperlinks

Post by Sapphon »

OK. I understand what you are saying.

-I should've been clearer about what I meant with "false GETs". Basically I am using a dynamically-generated hyperlink (say, ...viewword.php/?varx=1&vary=2&varz=3) that makes viewword.php think it's taking input from a GET-method form when it's not.

-Doing it with buttons instead of links makes sense. 2 follow-up questions:
1) Can it be done with hyperlinks, or are buttons/a form required when one wishes to use POST?
2) If buttons are necessary, I'd be interested in passing the words' database IDs to the next php page rather than their user-friendly descriptions. Is there a way for a button to have an appearance different from its actual value?

Thanks again.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP navigation question: POST and hyperlinks

Post by requinix »

Sapphon wrote:1) Can it be done with hyperlinks, or are buttons/a form required when one wishes to use POST?
Either you use JavaScript with the links or regular links and GET.
Sapphon wrote:2) If buttons are necessary, I'd be interested in passing the words' database IDs to the next php page rather than their user-friendly descriptions. Is there a way for a button to have an appearance different from its actual value?
Wow, that's the first time I've ever heard someone say they didn't want something user-friendly.
No, a button's text and a button's value are the same thing. Again, with JavaScript you can do whatever you want.


Look. Everything about what (I think) you're trying to do screams of putting the word in the URL and, therefore, using GET. The page should be cached, it's user-friendly, it's easier...
Why do you want POST for this? Why IDs and not words?
Sapphon
Forum Newbie
Posts: 4
Joined: Sun Jan 03, 2010 6:32 pm

Re: PHP navigation question: POST and hyperlinks

Post by Sapphon »

I'm now convinced (between your responses and what independent reading I've been able to do) that GET is the right way to do this. Thanks for your help!

In case you are curious, using the word's database ID is fairly important still, however, because words can be spelled identically but not be the same word (in English, for example, "Alternate" can mean "to switch back and forth" as in "Time alternates between AM and PM" and "another possible way" as in "I made the alternate choice") morphemically speaking.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP navigation question: POST and hyperlinks

Post by requinix »

Good point.

How about taking the URL-rewriting path?

Code: Select all

http://www.example.com/dictionary/123/alternate
The server is then told to treat that URL as

Code: Select all

/dictionary.php?id=123
Best of both worlds: using GET, with the ID, and with the word.
Sapphon
Forum Newbie
Posts: 4
Joined: Sun Jan 03, 2010 6:32 pm

Re: PHP navigation question: POST and hyperlinks

Post by Sapphon »

That's what I'll do.

I appreciate the prompt responses; I'll read some other threads and see if I can't help someone debug their code or something to keep the positive vibes going =)
Post Reply