/    Sign up×
Community /Pin to ProfileBookmark

POST data in <a>here</a> ???

At the moment I have a link like this.

[code=html]<a href=”page.php?key=val”>val</a>[/code]

Is it possible to send that query by the POST method so it keeps the URL bar tidy?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@pyroOct 18.2005 — If you are on an Apache server, you could look into mod_rewrite. Take a look at this: http://www.ryanbrill.com/archives/cruft-free-urls/
Copy linkTweet thisAlerts:
@ShmohelOct 18.2005 — That link necessarily is sending info through the GET method. If you want to keep your URL 'tidy' there are some work arounds you can do. Creating a form that submits with a link would probably be a lot of eeffort and not worth it.

But, you could send the variables into a session and then redirect the page. Or, you could use iframes. All would work.
Copy linkTweet thisAlerts:
@NogDogOct 18.2005 — Form method:
[code=html]
<style type="text/css">
<!--
body {
background-color: white;
color: black;
font: medium arial, sans-serif;
}
.link {
border: none;
background-color: white; /* set to same as surrounding background */
}
.link span {
color: blue;
text-decoration: underline;
font: medium arial, sans-serif; /* set same as surrounding text */
}
-->
</style>
</head>
<body>
<form action="page.php" method="post">
<p>This is a paragraph with a submit button that looks like a link:
<input type="hidden" name="key" value="val">
<button type="submit" class="link"><span>val</span></button>
</p>
</form>
[/code]
Copy linkTweet thisAlerts:
@bokehOct 18.2005 — Hmm. The mod_rewrite solution although it might make the url look tidier will still show some trace of the get data.

Shmohel's suggestion to use an iframe seems even more complex than a form, and to use sessions would assume one had already been started and that might not be the case.

The CSS solution is nicer but there are problems with it too. First it will be impossible to do any :hover effect in IE without javascript. Also it might not be too difficult styling the form into a paragraph but it would be a different matter putting it inside a floated element within a flyout menu or similar, specially considering how different browser vary in their handling of such elements. Another problem arises if styles are switched off. Because a form is a block level element if it is inside a paragraph and styles are disabled that paragraph will be fragmented into 3 pieces.

Personally I would recommend (gasp) a javascript solution. There would be no additional styling and if CSS were to be disabled it would just degrade gracefully back to the GET method. The form would not affect the page layout in any way whether styles were enabled or disabled. Here is the link:[code=php]<a href="http://domain.com/?param=val" onclick="
document.getElementById('formID').submit();
return false;"
>link</a>[/code]
And the following is the form. You would put it at the bottom of your page just before closing the </body> tag:[code=php]<form id="formID" action="http://domain.com/" method="post" style="display:none">
<div>
<input type="hidden" id="param" name="param" value="val" />
</div>
</form>[/code]
×

Success!

Help @Brain_Storm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...