Reputation: 10942
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
I think the &btn_show=Show
has something to do with the value of the submit element. Is there a way that I can remove or hide that in the Query string or 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);
}
Upvotes: 1
Views: 1108
Reputation: 4179
You can remove the name (e.g. name="btn_show"
) to remove the query string in the URL.
<input type="submit" id="bnt_show" value="Show" onclick="show(); "/>
Upvotes: 6
Reputation: 1318
Just complete your form tag by adding the method parameter. Eg. method="post"
. If you do so, the variables within the form will be passed to the web server by HTTP POST. Afterwards, you can find the variables within PHP in the $_POST
array.
Check out the following url for a complete FORM
Tag description.
http://www.w3schools.com/tags/tag_form.asp
Upvotes: 1
Reputation: 1375
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.
Upvotes: 1