如何将 PHP 变量加载到操作表单帖子中


How can you load a PHP variable into a action Form post?

我不确定我的语法做错了什么。 我正在尝试使用 url 帖子加载 PHP 值。

有没有办法发布<?php $_PHP_SELF ?>并将其加载到div 中而不使用 jquery 或 java? 这就是我想做的更多,但是如果你只能在帖子中放入一个php变量,那也会起作用。

<form role="form" method="post" action = "answerswer_audit.php?action=search&auditID=<?php $auditID ?>"  name="audit_search_form" id="audit_search_form"  >
    <input type="text" class="form-control"  name="audit_comments" />
    <input type="button" class="btn btn-default" name="submitID" id="submit_search" value="Search" />
</form>

目前,您的PHP代码正在获取$auditID变量,但实际上并没有对它做任何事情。您需要将其回显到页面。<?php echo $auditID ?><?= $auditID ?>都可以工作,假设您的服务器支持后者。

有没有办法在不使用jquery或java的情况下发布并加载到div中?

大概你的意思是Javascript,而不是Java,但没有。您需要发出 AJAX 请求才能将内容从 PHP 加载到页面中,而无需重新加载。

不知道为什么你想要过去的变量作为通过 POST 的 GET 参数,但尽管如此。没有办法将 php var 传递给 html 形式,除了 php var 的打印输出值到位是 html 值应该是。所以你应该这样做:

<form role="form" method="post" action = "answerswer_audit.php?action=search&auditID=<?php echo $auditID ?>"  name="audit_search_form" id="audit_search_form"  >

<form role="form" method="post" action = "answerswer_audit.php?action=search&auditID=<?= $auditID ?>"  name="audit_search_form" id="audit_search_form"  >

文档链接

有没有办法发布并将其加载到div 中 不使用jquery或java? 同样,您可以在任何您想要的 html 位置打印任何可用的 php。

<div><?=$_PHP_SELF?></div>

<div><?php echo $_PHP_SELF?></div>

关于帖子,不,html post 提交是客户端事件,php是服务器端引擎。但是有一种方法可以使用 curl 在 php 上完整地创建帖子

这里有一个小例子:

<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.example.com/tester.phtml");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "postvar1=value1&postvar2=value2&postvar3=value3");
// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
// further processing ....
if ($server_output == "OK") { ... } else { ... }
?>