How to insert a time from the suggested options into the datetime-local field

Viewed 48

I want to create a booking script and I can't solve the problem. There is a form field for the date, I output the available time slots separately from the database. I want the selected time to appear in the datetime-local field when choosing a timeenter image description here

          <div class="form-group">
            <label for="date_sched" class="control-label">Appointment</label>
            <input type="datetime-local" class="form-control" name="date_sched" value="" required>
        </div>
        
        
        <?
        
        $sched_set_qry = $conn->query("SELECT * FROM `schedule_settings`");
        $sched_set = array_column($sched_set_qry->fetch_all(MYSQLI_ASSOC),'meta_value','meta_field');
        $a = date("Y-m-d ") . explode(',',$sched_set['morning_schedule'])[0];
        $b = date("Y-m-d ") . explode(',',$sched_set['morning_schedule'])[1];
        
        
        $period =new DatePeriod (
        new DateTime($a),
        new DateInterval ('PT1H'),
        new DateTime ($b)
        );
        foreach ($period as $date){?>
            
            
             <input type="button" class="form-control" name="time" value="<? echo $date->format("H:i\n")?>"  >
    <?  }
        
        ?>
1 Answers

You need to use the select element such as

<label for="date-sched" class="control-label">Appointment:</label>

<select name="time" id="date-sched" class="form-control">
    <option value="">--Please choose an option--</option>
    <option value="08:00">08:00</option>
    <option value="09:00">09:00</option>
    <option value="10:00">10:00</option>
    <option value="11:00">11:00</option>
</select>

Not the label for refers to the id of the element, not the name. YOu can add as many options you like.

Related