0

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.

3
  • --nevermind, I see the anchor now; d'oh-- Commented Jul 19, 2011 at 17:13
  • Do you mean to have a form auto-fill itself upon submitting data to it, on a different page? Commented Jul 19, 2011 at 17:17
  • Yes, that would be cool. Commented Jul 19, 2011 at 17:53

3 Answers 3

1

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);
Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Thanks for your response. Nevertheless it behaves the same as it did before. New window with the form is displayed, but the form is not filled nor submitted. And java is now complaining that this.parentNode.submit(); is not a function.
@meridius: What browser are you using? And have you posted the exact code you're using? I have no problem in IE9, FF4&6 & Chrome
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.