I have the following code that basically consists of two input, two dates are placed independently. On the other hand, there is a select that works as a search filter, you must search for the entity that is selected between the two dates that were previously supplied. The problem is that when you select for the first time, you take them and show the results; However, when you reuse the same selection, when you click on the button and select the entity, you delete the dates that were initially set and you do not perform the search.
What I want is that you keep the dates each time you press the search button by entity -
<tr class="encabezadoT"> <td colspan=4>
<form method="POST" onsubmit="return validar(this)">
Desde: <input type="text" value="<?php if(isset($_POST['dp2'])){echo $_POST['dp2'];}?>" autocomplete='off' readonly id="dp2" name="dp2" style='width:120px' class="datepicker2" readonly >
Hasta: <input type="text" readonly autocomplete='off' id="dp1" name="dp1" value="<?php if(isset($_POST['dp1'])){ echo $_POST['dp1'];}?>" style='width:120px' class="datepicker2" >
<input class="boton2" id="boton2" type="submit" value="Buscar por fecha" id="fecha" name="fecha" >
</form>
</td>
<?php
if(isset($_POST['fecha'])){
$dp2=$_POST['dp2'];
$dp1=$_POST['dp1'];
}
?>
<form method="POST">
<select name=entidad id="entidad" >
<option disabled selected> Seleccione una entidad</option>
<option <?php if($entidad=="TODAS"){?>selected<?php }?>>TODAS</option>
<?php foreach($valor2 as $valor){//Mostrar en select la lista de los bancos
?><option <?php if($entidad==$valor){?>selected<?php }?>><?php echo $valor; ?></option> <?php } ?>
</select>
<input class="boton2" type="submit" name="boton2" value="Buscar">
<input type=hidden name=dp1 value='<?php echo $dp1?>'>
<input type=hidden name=dp2 value='<?php echo $dp2?>'>
</form>
<?php
$entidad='TODAS';
if(isset($_POST['boton2'])){
$entidad = $_POST['entidad'];
$dp2=$_POST['dp2'];
$dp1=$_POST['dp1'];
echo $entidad;
}
?>