How to send data using form in php?

Hello!
Php as a rookie, there is such a question)

I have a table with data and I do it filtration.
Deduce the form fields to filter and sort options:

<form action="allEmployees.php">

 <label for="pos">Position:</label>
 <select class="form-control" name="pos">
<?php
for($i=0;$i<count($pos);$i++){
 echo "<option name='$id'-->".$pos[$i]['title_pos']."";
}
?>
</select>
 <label for="type">Payment type:</label>
 <select class="form-control" name="type">
<?php
for($i=0;$i<count($types);$i++){
 echo "<option name='$id'-->".$types[$i]['title_type']."";
}
?>
</select>


 <p>Sorted data</p>
 <input type="radio" name="sorted" value="salary asc"> asc salary<br>
 <input type="radio" name="sorted" value="salary desc"> salary desc<br>
 <input type="radio" name="sorted" value="birthday asc"> asc birthday<br>
 <input type="radio" name="sorted" value="birthday desc"> desc birthday<br>

 br><button type="submit" class="btn btn-primary">Filter data</button>
 </form>


Here is the problem: if I want to sort the data and do not touch filters Payment type, Position I do not get.
In any case, the request data is transmitted on these values in the form ?pos=junior&type=rate

How to make these filters transmitted only if I choose and not the default?
July 2nd 19 at 18:09
1 answer
July 2nd 19 at 18:11
It is necessary to add a blank option c option is selected, then they will be selected by default:
<select class="form-control" name="pos">
<option value="Choose one" selected>
<?php
for($i=0;$i<count($pos);$i++){
 echo "<option name='$id'-->".$pos[$i]['title_pos']."</option>";
}
?>
</select>
 <label for="type">Payment type:</label>
 <select class="form-control" name="type">
 <option value="Choose one" selected>
<?php
for($i=0;$i<count($types);$i++){
 echo "<option name='$id'-->".$types[$i]['title_type']."</option>";
}
?>
 </select>


Plus I noticed a bug in cycles: you are using a variable $id and assign it to the name parameter, but logically it should be .$pos[$i]['id'] and $types[$i]['id'] with the assignment to the value parameter. Plus, you will discover a foreach loop:
<select class="form-control" name="pos">
<option value="Choose one" selected>
 <?php foreach($positions as $position): ?>
 </option><option value="<?= $position['id'] ?>"><?= $position['title_pos'] ?></option>
 <?php endforeach; ?>
</select>
 <label for="type">Payment type:</label>
 <select class="form-control" name="type">
 <option value="Choose one" selected>
 <?php foreach($types as $type): ?>
 </option><option value="<?= $type['id'] ?>"><?= $type['title_type'] ?></option>
 <?php endforeach; ?>
 </select>

Find more questions by tags PHP