我一直在這張桌子上對着桌子抨擊我的頭,而我的大腦從閱讀大量東西開始並沒有任何工作。從HTML文本輸入字段中存儲PHP變量
基本上,我需要從html輸入字段獲取輸入,將其分配給一個php變量,然後將該變量追加到url的末尾。到目前爲止,我沒有太多運氣!
<!DOCTYPE html>
<html>
<head>
<title>MyPage</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/black-tie/jquery-ui.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="//oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<!-- Sorry this is so ugly, I was trying to get it done fast, I can make another pass and smack it with a pretty stick later -->
<body>
<div class="jumbotron">
<div class="container">
<h1>My Super Page</h1>
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<p class="lead">Please Enter Some Text: </p>
<input type="text" name="input">
<input type="submit" data-toggle="modal" data-target="#myModal">
</form>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Results</h4>
</div>
<div class="modal-body">
Your Input Parsed:
<?php
$myInput = $_POST["input"];
echo $myInput;
$service_url = 'http://www.myapiservice/index.php/api/lookup?key=notreal&number='. $myInput;
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additional info: ' . var_export($info));
}
curl_close($curl);
echo $name;
$decoded = json_decode($curl_response, true);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
$myVar = $decoded["Response"]["dataset"];
if($myVar){
echo $myVar;
}
else {
echo 'Discarded Data';
}
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
</div>
</body>
</html>
所以會發生什麼,一旦你提交表單? –
您想在哪一行添加變量。另外,請僅發佈相關代碼,因爲很難在如此大的代碼中找出問題。 –
我需要在 這就是我真正需要的。其餘代碼完全按照預期工作,我只需要能夠將文本附加到API url的末尾。 –
goddesspapa