I wrestled a bear once.
I wrestled a bear once.

Reputation: 23379

Query string in form action when mixing POST and GET?

So I have a profile page: profile.php?pin=xx, where I use the GET method for determining which profile to display. I am going to test if $_SESSION['pin'] == $_GET['pin'] and if so, give the option to edit profile.

I don't want to write a-whole-nother script and direct the user to another page. So for usability sake, and keeping the server neat so I'm not always guessing which script does what, I want to mix POST and GET. I've done some research and it seems legal, but how?

<form method="post" action="profile.php?pin=xx">
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">

That's all I can think of without really getting the code messy.

Upvotes: 2

Views: 2045

Answers (1)

hakre
hakre

Reputation: 197659

If you keep the action attribute empty it will be the same URI including the GET parameters (query-info part of the URI):

<form method="post" action="">

Maybe this is what you're looking for? See HTML <form> tag for a reference about tag and attribute.

If you want to understand how that works: This is a so called Relative URI. It resolves to the Base URI of the document. As the Relative URI is empty, the Base URI is being taken over completely.

Upvotes: 5

Related Questions