我看了一些有关如何将变量从表单传递到php文件的教程,当我单击“提交”按钮时,什么也没发生。我正在制作一个页面,以搜索《部落冲突》 API,以显示所搜索的氏族。
我只需要将表单标签提交给php脚本即可。
这是我的代码。该文件是一个php文件,并且表单操作为空,因为php位于文件中。
<?php
header('Content-Type: text/html; charset=UTF-8');
if (isset($_POST['submit'])) {
$clantag = $_POST['var'];
}
$token = Token Goes Here;
$url = "https://api.clashofclans.com/v1/clans/" . urlencode($clantag);
$ch = curl_init($url);
$headr = array();
$headr[] = "Accept: application/json";
$headr[] = "Authorization: Bearer ".$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
$data = json_decode($res, true);
curl_close($ch);
echo "<pre>";
var_dump($data);
echo "</pre>";
?>
<form action="" method="post">
<input id="clan-tag" type="text" name="var" value="" />
<input id="clanSearchBtn" type="button" name="submit" value="Submit">
</form>
您应该将按钮的类型从“按钮”替换为“提交”
<form action="" method="post">
<input id="clan-tag" type="text" name="var" value="" />
<input id="clanSearchBtn" type="submit" name="submit" value="Submit">
</form>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句