Page 1 of 1
submiting post data through a link.
Posted: Wed Mar 17, 2004 8:17 am
by dull1554
has anyone ever herd of a way to submit post data through a regular linkrather then a form
Code: Select all
//a regular ling with GET data;
<a href=blah.php?get=yes&post=no>link</a>
//i want to be able to submit the same data through a link but have it sent as post data, if thats possiable.
thanks in advance
~~~Dull1554~~~
Posted: Wed Mar 17, 2004 8:23 am
by JAM
Perhaps this will give you more ideas?:
Code: Select all
<form method="post">
<input type="checkbox" name="get" value="yes">
<input type="checkbox" name="post" value="yes">
<input type="submit">
</form>
<?php
if (!empty($_POST)) {
print_r($_POST);
}
?>
If checked, it will display "yes", if not, nothing is displayed (in other words, "no"). Tweak it abit to fit you.
Posted: Wed Mar 17, 2004 8:27 am
by dull1554
well i was using the get yes and post no data as an example, im writing a memory game and when a user clicks on the card i want the card to flip, thats not my problem, so i have images as links, and i could submit the needed data through get in the link, but then a player could change the value of the get and make it easy for them to win, maybe there is a easy way to make the image my submit button and ill just use a loop to generate all the forms....
Re: submiting post data through a link.
Posted: Wed Mar 17, 2004 8:29 am
by TheBentinel.com
dull1554 wrote:has anyone ever herd of a way to submit post data through a regular linkrather then a form
I don't think you can do it with a straight link, but you can fake it with javascript link that submit's a post form:
Code: Select all
<form name=formpost action="myphp.php" method=post>
<input name=testpost type=text>
<input type=submit>
</form>
<a href="javascript:document.formpost.submit();">Submit the form via post</a>
It only works if the user has javascript enabled, and any onSubmit code on the form will not be fired.
Hope it helps!
Posted: Wed Mar 17, 2004 8:34 am
by basdog22
You can fake a link through a form like this:
<form name="form1" id="form1" method="post" action="">
<input name="imageField" type="image" src="link.gif" width="15" height="15" border="0" />
</form>
Just make some pictures that look like text and then pass any variable you wish

Posted: Wed Mar 17, 2004 8:56 am
by JAM
dull1554 wrote:well i was using the get yes and post no data as an example, im writing a memory game and when a user clicks on the card i want the card to flip, thats not my problem, so i have images as links, and i could submit the needed data through get in the link, but then a player could change the value of the get and make it easy for them to win, maybe there is a easy way to make the image my submit button and ill just use a loop to generate all the forms....
I was also using yes and no as example. After the above description of what you really are after, I'd also go with
TheBentinel.com's solution.
Posted: Wed Mar 17, 2004 10:46 am
by dull1554
thanks guys,
i think im gonna just use
Code: Select all
<input type='submit' name='submit' value='Continue' style="background: url(1.gif) no-repeat; width: 76; height: 101">
no extra steps involved....ya know easier....but thanks for all the help.
Posted: Wed Mar 17, 2004 11:58 am
by dull1554
i have decided to use TheBentinel.com's solution. but when i click on the link i get a error;
Code: Select all
line: 0
error: Object doesen't support this property or method.
///////////////////////////////////////////////////////////////////////
code im useing
<form name=form1 action=$PHP_SELF method=post>
<input type=submit name=submit>
</form>
<a href="javascript:document.form1.submit();">Submit the form via post</a>
any thoughts ?
Posted: Wed Mar 17, 2004 12:50 pm
by TheBentinel.com
dull1554 wrote:i have decided to use TheBentinel.com's solution. but when i click on the link i get a error;
ARGH!! I've spent the past half an hour working on this because I KNEW this worked. I finally found out the problem, but only because some other poor soul had the same problem.
Change the submit button's name to submitBtn. Or Bob. Or ANYTHING but "submit". When you fire document.form1.submit(), it's trying to run something on the button.
I gave you that button name in my sample code, it's all my fault. Argh! Double-Argh!
Change the name of the button and it should work.
Sorry!
Posted: Wed Mar 17, 2004 12:54 pm
by JAM
Also remember to put quotes around the values...
Code: Select all
// bad
<form method=post name=foo>
// better, and correct
<form method="post" name="foo">
Posted: Wed Mar 17, 2004 1:17 pm
by dull1554
got it
thanks a million
Posted: Wed Mar 17, 2004 1:39 pm
by d3ad1ysp0rk
couldnt you do..
Code: Select all
<form action="samepage.php" method="post">
<input type="hidden" name="pic" value="1">
<input type="image" src="pic1.jpg" border="0">
</form>
for each image?
Posted: Wed Mar 17, 2004 1:51 pm
by dull1554
how would i make it so that rather then having a submit button, having the image submit the form ?
Posted: Wed Mar 17, 2004 2:05 pm
by TheBentinel.com
dull1554 wrote:how would i make it so that rather then having a submit button, having the image submit the form ?
Do you mean with the <A href... thing? If so, then it's:
Code: Select all
<a href="javascript:document.form1.submit();">
<img src="submitImage.gif" width=50 height=50 border=0>
</a>
Posted: Wed Mar 17, 2004 2:29 pm
by Unipus
the IMAGE type of input element is (mostly) functionally equivalent to a SUBMIT button. There are a few practical differences, but clicking will still do the primary goal: submitting the form.
You could also style your traditional submit buttons with hidden text and a background image.