I want to pass several checkbox values from one form and visualize ourselves in another php file. I have 3 options:
- Entry Pass
- Exit Pass
- Missing
When you select Input Pass and Output Pass I have two variables chk[]
that allow me to capture the selected values, each option has a datepicker ( date[]
) and timepicker ( time[]
) except for Fault, which has just one datepicker ( date[]
).
What I want is that when you select a date[]
in the variable time, the value is "All day" because if a person fails to work it is understood that you only have to select a date and the time will be all day .
The problem is that when I put in the value="All day", if I select Pass or Exit Pass, at the end of the line I get "All day"
Is there any way this does not work out? If I select entry or exit pass, I must select time and date with date and time picker, but if I select Missing only choose Date Picker without putting me missing all day in the other two options.
Attach the code and a screenshot:
</div>
<label class="col-sm-2">Tipo de Pase</label>
<div class="col-sm-3">
<div class="form-check"><label class="form-check-label"><input class="form-check-input" id="pase_de_entrada" type="checkbox" name="chk[]" value="Pase de entrada" onchange="javascript:showContent()" /> Pase de Entrada </label>
</div>
<div class="form-check"><label class="form-check-label"><input class="form-check-input" id="pase_de_salida" type="checkbox" name="chk[]" value="Pase de salida" onchange="javascript:showContent1()" /> Pase de Salida </label>
</div>
<div class="form-check"><label class="form-check-label"><input class="form-check-input" id="falta_dia" type="checkbox" name="chk[]" value="Falta todo el dia" onchange="javascript:showContent2()" /> Falta <!---->
</label>
</div>
<div id="content2" style="display: none;">
<div class="form-group row" id="div3">
<label class="col-xs-12 col-sm-6 col-md-2 col-form-label" for="fecha_justificar">Fecha a Justificar Falta</label>
<div class="col-md-4"><input class="form-control" id="date3" name="date[]" placeholder="MM/DD/YYY" type="text" value=""/></div>
<link rel="stylesheet" href="jquerys/datepicker/css/bootstrap-datepicker3.css"/>
<script type="text/javascript" src="jquerys/datepicker/js/bootstrap-datepicker.min.js"></script>
<script>
$(document).ready(function(){
var date_input=$('input[name="date[]"]'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
var options={
format: 'dd/mm/yyyy',
container: container,
todayHighlight: true,
autoclose: true,
};
date_input.datepicker(options);
})
</script>
<input type="hidden" class="form-control" name="time[]" id="time3" value="Todo el dia">
<!--Si yo coloco en value ="Todo el dia" me aparece el valor aun no seleccionando el check "Falta"-->
</div>
</div>
and here the PHP
echo "<h1> Vista previa de los datos </h1>";
if (isset($_GET['enviar'])) {
if (is_array($_GET['chk'])) {
$selected = '';
$num_datos = count($_GET['chk']);
$current = 0;
foreach ($_GET['chk'] as $key => $value) {
if ($current != $num_datos-1)
$selected .= $value.' ';
else
$selected .= $value.' ';
$current++;
}
}
else {
$selected = 'Debes seleccionar una opcion';
}
echo '<div>Tipo de Pase seleccionado : '.$selected.'</div>';
}
if (isset($_GET['enviar'])) {
if (is_array($_GET['date'])) {
$selected1 = '';
$num_datos1 = count($_GET['date']);
$current1 = 0;
foreach ($_GET['date'] as $key1 => $value1) {
if ($current1 != $num_datos1-1)
$selected1 .= $value1.' ';
else
$selected1 .= $value1.' ';
$current1++;
}
}
else {
$selected1 = 'Debes seleccionar una opcion';
}
echo '<div>Fecha Solicitada: '.$selected1.'</div>';
}
if (isset($_GET['enviar'])) {
if (is_array($_GET['time'])) {
$selected2 = '';
$num_datos2 = count($_GET['time']);
$current2 = 0;
foreach ($_GET['time'] as $key2 => $value2) {
if ($current2 != $num_datos2-1)
$selected2 .= $value2.' ';
else
$selected2 .= $value2.' ';
$current2++;
}
}
else {
$selected2 = 'Debes seleccionar una opcion';
}
echo '<div>Horario Solicitado: '.$selected2.'</div>';
}
$fecha_de_solicitud=$_GET['fecha_de_solicitud'];
echo ' La fecha del alta del justificante es ' .$fecha_de_solicitud.'';
echo '<br>';
?>