PDA

View Full Version : Using $_POST instead of $_GET


qazs
12-19-2004, 03:12 PM
hi, i want to know how i can use POST instead of GET to
pass variables in between my website.
Let's say I have 3 links, 'a','b' and 'c'.
Currently, im using this:
<a href=link.php?value=a>a</a>
<a href=link.php?value=b>b</a>
<a href=link.php?value=c>c</a>

So how can I use the POST method to do this?
I'm thinking of using hidden value like this:
<input type='hidden' name='field' value='$value'>
since I can use PHP to modify the value field.
But I don't know how to go about doing it.

Thanks for any help.

AaronW
12-19-2004, 03:47 PM
Could you elaborate on why you've decided POST would be better? Using a form for every link is really really ugly.

qazs
12-19-2004, 03:56 PM
Ummm, but with a url like this:
http://link.php?a=a&b=b&c=c&d=d&e=e&f=f.....
can also be a bit ugly.....

xiaodao
12-19-2004, 04:01 PM
:D yap, but how come got so many

qazs
12-19-2004, 04:08 PM
It's a bit exaggerating... but it's a rough idea.
So, how can I use the POST method??
I'm thinking of making every link a submit button, not those
grey dialogue boxes, but as normal links.
But i dont know how to do it....

fci
12-19-2004, 04:08 PM
you should post your code because your current method works but seems to have a bug[I think, won't know til you post the code so we can take a closer look].

marek_mar
12-19-2004, 04:24 PM
Huh?? POST is not a method in php. It's just a way of geting variable that were sent from the user using the post method. It's used in forms when some data cant be visible in the address box.
You choose the method (GET or POST) in HTML.

You could submit a form with a normal link using javascript eg. <a href="#" onClick="document.myForm.submit()">Submit</a>

qazs
12-19-2004, 04:29 PM
Wait.... i know that piece of code is ok.
But to get those values, i have to use $_GET right?
What I want instead is to use $_POST, like when you submit a form,
but just that there won't be any query string behind.

marek_mar
12-19-2004, 04:38 PM
_GET is an array that holds all the values recieved using the get method.
_POST is an array that holds all the values recieved using the post method.
_COOKIE is an array that holds all the values recieved from cookies.
_REQUEST is all of those put into one.

You don't set the mode in php.

qazs
12-19-2004, 04:59 PM
ok, so let's say i use:
<a href="#" onClick="document.myForm.submit()">Submit</a>
How can I have a POST value of the link I've clicked?
FOr eg:
<a href="#" onClick="document.myForm.submit()">a</a>
I will get a POST value of 'a'.

marek_mar
12-19-2004, 05:20 PM
This should work (I don't normally use js for submiting forms):

<form name="myForm" action="some.php" method="post">
<input type="hidden" name="a" value="a" />
</form>
<a href="#" onClick="document.myForm.submit()">a</a>

AaronW
12-19-2004, 06:13 PM
...

It's suicide for your site though. Search engines wouldn't touch those links with a 10-foot digipole, and how're people supposed to share links to specific pages on your site? It pretty much becomes a flash site, in that you can only link the front page...

If you're worried about ugliness, either rethink your site's content management, or try something like mod_rewrite on your URLs (so I can visit yoursite.com/a/b/c while your site actually sees yoursite.com/page.php?var=a&var2=b&var3=c).

Ugly links or a usuable site? Your choice, but do consider the consequences.

qazs
12-22-2004, 01:40 PM
Search engines wouldn't touch those links with a 10-foot digipole

What do you mean by '10-foot digipole'?

Regarding whether the links are reachable to the users, there is
no worry because there are really no sub web pages.