submiting post data through a link.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

submiting post data through a link.

Post 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~~~
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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....
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: submiting post data through a link.

Post 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!
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post 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 :wink:
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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 ?
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post 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!
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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">
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

got it
thanks a million
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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?
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

how would i make it so that rather then having a submit button, having the image submit the form ?
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post 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>
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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.
Post Reply