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!
PHP navigation question: POST and hyperlinks
Moderator: General Moderators
Re: PHP navigation question: POST and hyperlinks
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:
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>Re: PHP navigation question: POST and hyperlinks
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.
-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.
Re: PHP navigation question: POST and hyperlinks
Either you use JavaScript with the links or regular links and GET.Sapphon wrote:1) Can it be done with hyperlinks, or are buttons/a form required when one wishes to use POST?
Wow, that's the first time I've ever heard someone say they didn't want something user-friendly.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?
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?
Re: PHP navigation question: POST and hyperlinks
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.
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.
Re: PHP navigation question: POST and hyperlinks
Good point.
How about taking the URL-rewriting path?
The server is then told to treat that URL as
Best of both worlds: using GET, with the ID, and with the word.
How about taking the URL-rewriting path?
Code: Select all
http://www.example.com/dictionary/123/alternateCode: Select all
/dictionary.php?id=123Re: PHP navigation question: POST and hyperlinks
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 =)
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 =)