[英]How to remove unnecessary strings in Query String in PHP?
I am a total noob in programming so pls be patient with me. 我是编程的新手,请耐心等待。 My question might look stupid to you.
我的问题对您可能看起来很愚蠢。
I have here a query string: 我这里有一个查询字符串:
http://localhost/exercises/php_js/exer_test/?year_list=1994&event_list=Singing+Contest&btn_show=Show
http:// localhost / exercises / php_js / exer_test /?year_list = 1994&event_list = Singing + Contest&btn_show = Show
I think the &btn_show=Show
has something to do with the value of the submit element. 我认为
&btn_show=Show
元素的值有关。 Is there a way that I can remove or hide that in the Query string or URL? 有没有一种方法可以删除或隐藏在查询字符串或URL中?
index.php
<?php include('functions.php'); ?>
<html>
<head>
<script type="text/javascript" src="myscripts.js"></script>
</head>
<body>
<div>
<form name="myform" >
Select Year: <?php echo hspacer(1); ?>
<select id="year_list" name="year_list" >
<?php
for($year = (date('Y') - 100); $year <= (date('Y') + 100); $year++ ) {
if ($year == date('Y')) echo "<option value='$year' name='$year' selected='' >" . $year . "</option>";
else echo "<option value='$year' name='$year' >" . $year . "</option>";
}
?>
</select>
<?php echo hspacer(5); ?>
Select Event: <?php echo hspacer(1); ?>
<select id="event_list" name="event_list" >
<?php
$events = array("Karate Tournament", "Beauty Pageant", "Film Festival", "Singing Contest", "Wedding");
foreach($events as $event) echo "<option value='$event' name='$event' >" . $event . " </option>";
?>
</select>
<?php echo vspacer(2); echo hspacer(22); ?>
<input type="submit" id="bnt_show" name="btn_show" value="Show" onclick="show(); "/>
</form>
</div>
</body>
</html>
functions.php
<?php
function hspacer($num_of_spaces) {
$spaces = "";
if ($num_of_spaces > 0) for($i=0; $i<$num_of_spaces; $i++ ) $spaces .= " ";
return $spaces;
}
function vspacer($num_of_linefeeds) {
$linefeeds = "";
if ($num_of_linefeeds > 0) for($i=0; $i<$num_of_linefeeds; $i++ ) $linefeeds .= "<br />";
return $linefeeds;
}
?>
myscripts.js
function show() {
var year = document.getElementById('year_list').value;
var event = document.getElementById('event_list').value;
var result = "Year: " + year + "\nEvent: " + event;
alert(result);
}
您可以删除名称(例如name="btn_show"
)以删除URL中的查询字符串。
<input type="submit" id="bnt_show" value="Show" onclick="show(); "/>
只需从“提交”按钮元素中删除name
即可。
Just complete your form tag by adding the method parameter. 只需通过添加method参数来完成表单标签。 Eg.
例如。
method="post"
. method="post"
。 If you do so, the variables within the form will be passed to the web server by HTTP POST. 如果这样做,表单中的变量将通过HTTP POST传递到Web服务器。 Afterwards, you can find the variables within PHP in the
$_POST
array. 之后,您可以在
$_POST
数组中的PHP中找到变量。
Check out the following url for a complete FORM
Tag description. 请查看以下网址以获取完整的
FORM
标签说明。
http://www.w3schools.com/tags/tag_form.asp http://www.w3schools.com/tags/tag_form.asp
Yes, if you are not using the value, remove the value from the input element of the submit button, or use the button-tag. 是的,如果您不使用该值,请从“提交”按钮的输入元素中删除该值,或使用按钮标签。
If you are using the value it would be correct to put it in the url as well. 如果您使用的是值,那么将其也正确地放置在url中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.