如何使用 PHP 提交表单?

发布于 2024-10-05 01:46:35 字数 1188 浏览 1 评论 0原文

<form style="text-align:center;" id="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="POST">
    <input type='hidden' name='cmd' value='_xclick'>
    <input type='hidden' name='business' value='[email protected]'>
    <input type='hidden' name='item_name' value='201001114262121'>
    <input type='hidden' name='amount' id="amount" value='1.00'>
    <input type='hidden' name='currency_code' value='CAD'>
    <input type='hidden' name='return' value='http://www.xxx.com/paypal_process.php'>
    <input type='hidden' name='invoice' value='82'>
    <input type='hidden' name='charset' value='utf-8'>
    <input type='hidden' name='no_shipping' value='1'>
    <input type='hidden' name='no_note' value=''>
    <input type='hidden' name='notify_url' value='http://www.xxx.com/return.php'>
    <input type='hidden' name='rm' value='82'>
    <input type='hidden' name='cancel_return' value='http://www.xxx.com/index.html'>
</form>

有人知道吗?

<form style="text-align:center;" id="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="POST">
    <input type='hidden' name='cmd' value='_xclick'>
    <input type='hidden' name='business' value='[email protected]'>
    <input type='hidden' name='item_name' value='201001114262121'>
    <input type='hidden' name='amount' id="amount" value='1.00'>
    <input type='hidden' name='currency_code' value='CAD'>
    <input type='hidden' name='return' value='http://www.xxx.com/paypal_process.php'>
    <input type='hidden' name='invoice' value='82'>
    <input type='hidden' name='charset' value='utf-8'>
    <input type='hidden' name='no_shipping' value='1'>
    <input type='hidden' name='no_note' value=''>
    <input type='hidden' name='notify_url' value='http://www.xxx.com/return.php'>
    <input type='hidden' name='rm' value='82'>
    <input type='hidden' name='cancel_return' value='http://www.xxx.com/index.html'>
</form>

Anyone knows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一紙繁鸢 2024-10-12 01:46:35
<?php
if(isset($_POST['submit']))
{
    function do_post_request($url, $data, $optional_headers = null)
    {
        $params = array('http' => array(
                        'method' => 'POST',
                        'content' => $data
                    ));
        if($optional_headers != null)
        {
            $params['http']['header'] = $optional_headers;
        }
        $ctx = stream_context_create($params);
        $fp = @fopen($url, 'rb', false, $ctx);
        if (!$fp)
        {
            throw new Exception("Problem with $url, $php_errormsg");
        }
        $response='';
        while (!feof($fp))
        {
            $response = $response.fgets($fp);
        }
        if ($response === false)
        {
            throw new Exception("Problem reading data from $url, $php_errormsg");
        }

        fclose($fp);
        return $response;
    }
    $host = 'http://mydomain.com';
    $url = 'http://mydomain.com/formHandler.php';
    $username = 'admin';
    $password = '123456';
    $data = array ('action' => 'login','lgname' => $username, 'lgpassword' => $password, 'format' => 'txt');
    $data = http_build_query($data);
    $reply = do_post_request($url, $data);
    echo "**********Response*********<pre>";
    echo var_dump($reply);
    #header('location:'.$host);
    #exit;

   } else {
       echo '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'"><input type="text" name="uname" /><br><input type="password" name="password" /><input type="submit" name="submit"></form>';
   }

 ?>

试试这个

<?php
if(isset($_POST['submit']))
{
    function do_post_request($url, $data, $optional_headers = null)
    {
        $params = array('http' => array(
                        'method' => 'POST',
                        'content' => $data
                    ));
        if($optional_headers != null)
        {
            $params['http']['header'] = $optional_headers;
        }
        $ctx = stream_context_create($params);
        $fp = @fopen($url, 'rb', false, $ctx);
        if (!$fp)
        {
            throw new Exception("Problem with $url, $php_errormsg");
        }
        $response='';
        while (!feof($fp))
        {
            $response = $response.fgets($fp);
        }
        if ($response === false)
        {
            throw new Exception("Problem reading data from $url, $php_errormsg");
        }

        fclose($fp);
        return $response;
    }
    $host = 'http://mydomain.com';
    $url = 'http://mydomain.com/formHandler.php';
    $username = 'admin';
    $password = '123456';
    $data = array ('action' => 'login','lgname' => $username, 'lgpassword' => $password, 'format' => 'txt');
    $data = http_build_query($data);
    $reply = do_post_request($url, $data);
    echo "**********Response*********<pre>";
    echo var_dump($reply);
    #header('location:'.$host);
    #exit;

   } else {
       echo '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'"><input type="text" name="uname" /><br><input type="password" name="password" /><input type="submit" name="submit"></form>';
   }

 ?>

Try this

枯寂 2024-10-12 01:46:35

如果您希望在页面加载后立即提交此表单,并且您决定使用 PHP 提交表单,则可以将其添加到页面底部:

<?
echo "<script type=\"text/javascript\"> 
                window.onload=function(){
                    document.forms['paypalform'].submit();
                }
       </script>";
?>

但这似乎还有很长的路要走。你可以将 javascript 写入页面...也许我不确定你想要做什么,但我想我会把它扔掉。

If you're wanting this form to submit as soon as the page is loaded, you can add this to the bottom of the page if you're determined in using PHP to submit the form:

<?
echo "<script type=\"text/javascript\"> 
                window.onload=function(){
                    document.forms['paypalform'].submit();
                }
       </script>";
?>

But that seems like a long way around it. You could just write the javascript into the page... maybe I'm not sure what you're wanting to do, but I thought I'd throw this out.

孤蝉 2024-10-12 01:46:35

使用 javascript,您可以在 PHP 代码中提交表单,如下所示:
(技巧在最后一行)

    $paypalURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    $paypalID = '[email protected]';
    $form = "<form id='paypal' action='". $paypalURL."' method='post'>";
    $form .='<input type="hidden" name="business" value="'. $paypalID.'">';
    $form .='<input type="hidden" name="cmd" value="_xclick">';
    $itemDetail = "Detail goes here";
    $orderId = 4444;
    $totalAmountWithFee = 55;
    $form .='<input type="hidden" name="item_name" value=" '.$itemDetail.'">
        <input type="hidden" name="item_number" value="'.$orderId.'">
        <input type="hidden" name="amount" value="'.$totalAmountWithFee.'">
        <input type="hidden" name="currency_code" value="USD">';

    $form .="<input type='hidden' name='cancel_return' value='http://localhost/public/cancel.php'> <input type='hidden' name='return' value='http://localhost/success.php'>";
    $form.="<script type=\"text/javascript\"> document.forms['paypal'].submit();</script>";
    echo $form;

如果有人有好主意请分享。

Using javascript you can submit the form inside PHP code like this:
(trick is in last line )

    $paypalURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    $paypalID = '[email protected]';
    $form = "<form id='paypal' action='". $paypalURL."' method='post'>";
    $form .='<input type="hidden" name="business" value="'. $paypalID.'">';
    $form .='<input type="hidden" name="cmd" value="_xclick">';
    $itemDetail = "Detail goes here";
    $orderId = 4444;
    $totalAmountWithFee = 55;
    $form .='<input type="hidden" name="item_name" value=" '.$itemDetail.'">
        <input type="hidden" name="item_number" value="'.$orderId.'">
        <input type="hidden" name="amount" value="'.$totalAmountWithFee.'">
        <input type="hidden" name="currency_code" value="USD">';

    $form .="<input type='hidden' name='cancel_return' value='http://localhost/public/cancel.php'> <input type='hidden' name='return' value='http://localhost/success.php'>";
    $form.="<script type=\"text/javascript\"> document.forms['paypal'].submit();</script>";
    echo $form;

If someone has a good idea pls share.

姜生凉生 2024-10-12 01:46:35

您可以使用 fsubmit PHP 库从 php 提交 HTML 表单 https://github.com/randomsymbols/fsubmit

require_once 'fsubmit.php';
$html = '<form action="backend.aspx" method="post"><input type="text" name="question"></form>';
$form = new Fsubmit();
$form->url = 'http://the_url_must_contain_action_url_base'; // If form action is a relative link, then url is a required parameter, if form action is an absolute link, then this parameter can be omitted
$form->html = $html;
$form->params = ['question' => 'To code or not to code?', 'extra_question' => 'In what language?'];
$answer = $form->submit();
echo $answer['content'];

You can submit an HTML form from php with fsubmit PHP library https://github.com/randomsymbols/fsubmit

require_once 'fsubmit.php';
$html = '<form action="backend.aspx" method="post"><input type="text" name="question"></form>';
$form = new Fsubmit();
$form->url = 'http://the_url_must_contain_action_url_base'; // If form action is a relative link, then url is a required parameter, if form action is an absolute link, then this parameter can be omitted
$form->html = $html;
$form->params = ['question' => 'To code or not to code?', 'extra_question' => 'In what language?'];
$answer = $form->submit();
echo $answer['content'];
混吃等死 2024-10-12 01:46:35

您可以使用 cURL 或此库(基于 cURL 和简单的 html dom)从 PHP 脚本提交 HTML 表单。

You can submit an HTML form from a PHP script with cURL or this library (that is based on cURL and simple html dom).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文