我有一个关于在表单提交上使用 PHP_SELF 的问题。这就是我在index.php中的内容:
<body>
<div class="container">
<div class="row">
<div class="span12">
<?php
// If you get an appid,
if(isset($_GET['appid'])) {
// GET appid
$appid = $_GET['appid'];
$json_url ='http://api.nameurl.com/api/gateway/call/1.4/getApp?appid=' . $appid;
$ch = curl_init($json_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$str = curl_exec($ch);
curl_close($ch);
$data = json_decode($str);
$array = json_encode($data);
}
else if(isset($_POST['submit'])){
$name = $_POST['appid'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
echo "<br>You can use the following form again to enter a new name.";
}
else{ ?>
<!-- Form -->
<form class="well" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label>Your appid</label>
<input type="text" class="span3" name="appid" id="appid" placeholder="Type your appid here..."> <br>
<button type="submit" id="submit" class="btn btn-primary" data-loading-text="Loading...">Submit</button>
</form>
<?php }
?>
<p id="errors" class="text-error"></p>
</div>
</div>
<hr>
</div>
我检查我是否从上一页获得了 appid。
是 -> 从 api 获取数据
否 -> 显示表单以便您可以插入 appid
然后,当您在表单上按提交时,我想获取 appid 插入并执行与上述相同的操作。
我究竟做错了什么?