Hi guy
I've been having a weird situation for a couple of day...
I have this button that is suppose to pass parameter in the $_GET array but it doesn't.
Here is the code:

<html>
<body>
<form action="test.php?action=test" method="get">
<input type="submit" value="Test"/>
</form>
</body>
</html>

what happens when clicking on the button is that the test.php
page is loaded, but no parameter e.g. action=test are found neither in the url nor in $_GET...

Thanks in advance for your help
Silh

nav33n commented: Good question! +10

Recommended Answers

All 13 Replies

Try this:

<html>
<body>
<form action="test.php" method="get">
<input type="hidden" name="action" value="test">
<input type="submit" value="Test"/>
</form>
</body>
</html>

Yeah it works !
thanks a lot
but just for the sake of it
why do you think the other code doesn't work?
I've also tried with input type=button that worked in another script but not in this one...
I don't know... I was thinking that it might be a problem of encoding since it works if I change ? with & .... and that's something that I've never seen on earth...
just for reference I am using notepad++
anyway thanks for the reply I will use your code.
Tnx

have you tried post method?

yeah
post is not working either.
it cannot be the server because i ve got the same problem on wamp...
the code is right because it works on another script...
i mean old script work all the script I am writing since yesterday give me this problem... that's why I am thinking about a notepad++ problem
I am totally lost !!!

why do you think the other code doesn't work?

The reason is that you cannot pass url variables through the action= but I am not sure if it is the same with the post method though.

The reason is that you cannot pass url variables through the action= but I am not sure if it is the same with the post method though.

It works fine with post method.

<?php
echo $_GET['action'];
?>
<html>
<body>
<form action="test.php?action=test" method="post">
<input type="submit" value="Test"/>
</form>
</body>
</html>

Is there any technical explanation for this ?

when you will use post method and will request the variable it will give you value e.g

<? echo "show value--------".$_REQUEST['action'];?> OR
<? echo "show value--------".$_GET['action'];?>

<form action="test.php?action=test" method="[B]post[/B]">
<input type="text" value="testing" name="hello" />

<input type="submit" value="Test"/>
</form>

this will show the value in your variable.

when you will apply get method instead of post

<form action="test.php?action=test" method="[B]get[/B]">
<input type="text" value="testing" name="hello" />

<input type="submit" value="Test"/>
</form>

this will give you the value of objects exist in your form not the value of action "test.php?action=test"

copy and paste the code and check the difference

this will give you the value of objects exist in your form not the value of action "test.php?action=test"

But when you use post method, how could it get the action value from form action along with other form elements ?

No i am talking about Get method in this case..... when use POST method then it cant

Well to help answer the questions of why the action= will go to test.php?action=test only when method=post is that when method=get, the parameters in the form overwrite the parameters specified in the action=. However, when using method=post, there are no parameters that can possibly overwrite the action= since it is posting them. So basically it is a browser problem and not a server problem.

commented: correct.. +10

No i am talking about Get method in this case..... when use POST method then it cant

Umm! Let me clear the misunderstanding. This works. The form method is POST and action = test.php?action=test.

<?php
echo $_GET['action'];
?>
<html>
<body>
<form action="test.php?action=test" method="post">
<input type="submit" value="Test"/>
</form>
</body>
</html>

But this doesn't work. The form method is get and action is test.php?action=test.

<?php
echo $_GET['action'];
?>
<html>
<body>
<form action="test.php?action=test" method="get">
<input type="submit" value="Test"/>
</form>
</body>
</html>

My question is, why doesn't GET method go to the action test.php?action=test ?

Well to help answer the questions of why the action= will go to test.php?action=test only when method=post is that when method=get, the parameters in the form overwrite the parameters specified in the action=. However, when using method=post, there are no parameters that can possibly overwrite the action= since it is posting them. So basically it is a browser problem and not a server problem.

Hmm! That answer looks convincing. I guess you are right.

Wooow
tnx a lot cwarn23 that's the explanation that I wanted...
I ve learnt more this morning than in the last 2 weeks :)
I wonder why that's not explained in basic php or even html manuals...
well thank you guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.