So I have made a form where staff members can post activities like soccer or tennis with a form. So I have 2 dates which they can select. The first date is the start date of the activity and the second date is the end date of the activity. I don't want it to be able to select an end date earlier than a selected startdate. So for example I want to fill in an activity like bowling and it in the form I put at the start date 03-04-2018 and the end date 02-02-2018, I don't want that to be possible.
This is how my form looks:
<?php echo form_open('index.php/Jongeren_activiteiten/Add_activiteit'); ?>
<br>
<center>Naam van activiteit:</center>
<div class="form-group">
<input class="form-control" name="activiteit" id="activiteit" type="text">
</div>
<center>Begindatum:</center>
<div class="form-group">
<input class="form-control" name="begindatum" id="begindatum" placeholder="Startdatum cursus" type="date">
</div>
<center>Einddatum:</center>
<div class="form-group">
<input class="form-control" name="einddatum" id="einddatum" placeholder="einddatum cursus" type="date">
</div>
<div>
<button class="btn btn-primary" name="Add_activiteit" >Toevoegen</button>
</div>
</form>
And this is the controller function of the form:
public function Add_activiteit()
{
if (isset($_POST['Add_activiteit'])) {
$this->form_validation->set_rules('activiteit', 'Activiteit', 'required');
$this->form_validation->set_rules('begindatum', 'Begindatum', 'required');
$this->form_validation->set_rules('einddatum', 'Einddatum', 'required');
//If form validation true
if ($this->form_validation->run() == TRUE) {
// echo 'form validated';
$data = array (
'activiteit'=>$_POST['activiteit'],
'begindatum'=>$_POST['begindatum'],
'einddatum'=>$_POST['einddatum'],
);
$this->db->insert('activiteit',$data);
$this->session->set_flashdata("success", "u heeft een nieuwe activiteit toegevoegd");
redirect("index.php/Jongeren_activiteiten", "refresh");
}
}
}
begindatum means start date and einddatum means end date. So how do I fix it so you can only select an end date later than a startdate? I also don't want people to being able select a day in the past.
Any kind of help is appreciated