php 使用 html 下拉选项卷曲填充变量
php curl populating variables with html drop down selection
我是 php 的新手,正在尝试从 html 下拉表单中获取要填充的 php curl 请求变量。我希望此请求在选择时重新加载页面。下面的代码给出了这个错误
select.php:19 Uncaught TypeError: document.getElementById(...).submit
is not a function
at change (select.php:19)
at HTMLSelectElement.onchange (select.php:10)
<html>
<head>
</head>
<body>
<form method="post">
<select id="wipname2" name="wipname2" style='position: relative' onchange="change()">
<option value="site1.com">site1.com</option>
<option value="site2.com">site2.com</option>
<option value="site3.com">site3.com </option>
</select>
</form>
<script>
function change(){
document.getElementById("wipname2").submit();
}
</script>
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
//CURLOPT_URL => 'https://example.com/MagicService/rest/ltmNode?wipNames='.$_GET["wipnames2"],
CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=".'$_GET["wipnames2"]',
// CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=content.gslb.fmr.com",
// CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=$value",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Cache-Control: no-cache",
"access-token: df11c69eabb9eab4abaf4bcc6b1e62a26025e830",
"password: ",
"username: "
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
//fwrite($output,$response);
//print_r (explode(" ",$response));
echo $response;
}
?>
</body>
</html>
submit()
是对表单中带有name="submit"
的文本输入的引用。
将 <input type="hidden" name="submit" value="submit" />
放入表单中,然后它就可以工作了。
reference
问题出在这段代码 document.getElementById("wipname2").submit();
上。 wipname
是一个 select
控件,它没有 submit
事件。但是您在 form
中拥有该控件,因此只需进行一些小的更改即可使其工作:
- 您可以将
<form method="post">
更改为 <form id="theForm" method="post">
以便向您的表单添加标识符 (id
)。
- 然后将
change
函数中的 document.getElementById("wipname2").submit();
更改为 document.getElementById("theForm").submit();
以触发 form
提交事件。
我是 php 的新手,正在尝试从 html 下拉表单中获取要填充的 php curl 请求变量。我希望此请求在选择时重新加载页面。下面的代码给出了这个错误
select.php:19 Uncaught TypeError: document.getElementById(...).submit is not a function at change (select.php:19) at HTMLSelectElement.onchange (select.php:10)
<html>
<head>
</head>
<body>
<form method="post">
<select id="wipname2" name="wipname2" style='position: relative' onchange="change()">
<option value="site1.com">site1.com</option>
<option value="site2.com">site2.com</option>
<option value="site3.com">site3.com </option>
</select>
</form>
<script>
function change(){
document.getElementById("wipname2").submit();
}
</script>
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
//CURLOPT_URL => 'https://example.com/MagicService/rest/ltmNode?wipNames='.$_GET["wipnames2"],
CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=".'$_GET["wipnames2"]',
// CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=content.gslb.fmr.com",
// CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=$value",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Cache-Control: no-cache",
"access-token: df11c69eabb9eab4abaf4bcc6b1e62a26025e830",
"password: ",
"username: "
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
//fwrite($output,$response);
//print_r (explode(" ",$response));
echo $response;
}
?>
</body>
</html>
submit()
是对表单中带有name="submit"
的文本输入的引用。
将 <input type="hidden" name="submit" value="submit" />
放入表单中,然后它就可以工作了。
reference
问题出在这段代码 document.getElementById("wipname2").submit();
上。 wipname
是一个 select
控件,它没有 submit
事件。但是您在 form
中拥有该控件,因此只需进行一些小的更改即可使其工作:
- 您可以将
<form method="post">
更改为<form id="theForm" method="post">
以便向您的表单添加标识符 (id
)。 - 然后将
change
函数中的document.getElementById("wipname2").submit();
更改为document.getElementById("theForm").submit();
以触发form
提交事件。