hyperlink to submit form on a different page
Is there a way how link can post data to a form on different page?
I imagine something like this, but this only open the requested page in new window (which is fine), but leaves the form on that page unfilled and also unsubmitted.
<?php echo '
<form action="http://www.someweb.cz/info2/dochazka/dochazka.php" method="post">
<input name="obdobi" type="hidden" value="'.$obdobi[Obdobi].'" />
<input name="kurs" type="hidden" value="'.$kurz_vybrany.'" />
<a target="_blank" style="开发者_开发问答text-decoration:none;"
href="http://www.someweb.cz/info2/dochazka/dochazka.php?doc=start.htm"
onclick="this.form.submit();">'.$pocet_lidi.'</a>
</form>'; ?>
I can slightly modify the "action" page code, but I'd like to keep the POST method.
This is easy to accomplish via cURL. See Example #2 on the manual page:
$ch = curl_init();
$data = array('obdobi' => $obdobi[Obdobi],
'kurs' => $kurz_vybrany);
curl_setopt($ch, CURLOPT_URL, 'http://www.someweb.cz/info2/dochazka/dochazka.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
You can change your javascript a bit, since the use of this
is actually referring to the anchor itself and not the window, the form, etc. (thus calling this.form
isn't actually capturing the form, it's giving an undefined error).
<form action="http://www.google.com" method="GET">
<input type="text" name="q" />
<a href="http://www.stackoverflow.com" target="_blank" onClick="this.parentNode.submit();">Submit</a>
</form>
Note the parentNode
reference after this. Note this demo.
I could not get either of suggested working. And because this was only a part of bigger project with deadline closing I decided to solve this by removing form, updating anchor to
<a target="_blank" style="text-decoration:none;"
href="http://www.someweb.cz/info2/dochazka/dochazka.php
?doc=start.htm&obdobi='.$obdobi[Obdobi].'&kurs='.$kurz_vybrany.'">'.$pocet_lidi.'</a>
and adding
<?php
if (isset($_GET[kurs])) $kurs = $_GET[kurs];
if (isset($_GET[obdobi])) $obdobi = $_GET[obdobi];
?>
to dochazka.php
精彩评论