Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:01:15+00:00 2026-06-17T22:01:15+00:00

i want to validate 2 date input in codeigniter, with the conditions, if the

  • 0

i want to validate 2 date input in codeigniter, with the conditions, if the end date is greater than the start date, will appear warning [javascript warning or something] or data can’t be input

my form like this,

<h1><?php echo $title; ?></h1>
<form action="<?= base_url(); ?>index.php/admin/kalender/buat" method="post" enctype="multipart/form-data" name="form" id="form">
<?php
echo "<p><label for='IDKategori'>Tingkatan Pimpinan :</label><br/>";
echo form_dropdown('IDKategori', $kategori) . "</p>";

echo "<label for='ptitle'>Kegiatan / Lokasi :</label><br/>";
$data = array('class' => 'validate[required] text-input', 'name' => 'judul', 'id' => 'ptitle', 'size' => 80);
echo form_input($data);

echo "<p><label for='long'>Uraian Kegiatan / Keterangan / Catatan :</label><br/>";
$data = array('class' => 'validate[required] text-input', 'name' => 'konten', 'rows' => '13', 'cols' => '60', 'style' => 'width: 60%');
echo form_textarea($data) . "</p>";

echo "<p><label for='ptitle'>Waktu Mulai :</label><br/>";
$data = array('class' => 'validate[required] text-input', 'name' => 'TanggalMulai', 'id' => 'basic_example_1');
echo form_input($data) . "</p>";

echo "<p><label for='ptitle'>Waktu Akhir :</label><br/>";
$data = array('class' => 'validate[required] text-input', 'name' => 'TanggalAkhir', 'id' => 'basic_example_2');
echo form_input($data) . "</p>";

echo form_submit('submit', 'Tambah Even');
?>
&nbsp;&nbsp;<input type="button" value="Kembali" onClick="javascript: history.go(-1)" />

how to validate in form “Waktu Akhir & Waktu Mulai” ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:01:16+00:00Added an answer on June 17, 2026 at 10:01 pm

    Try this. It is by using CI validation library.
    It uses callback type of validation.

    Put this in if(isset($_POST['submit_button_name'])) {} section.
    First, load validation array,

    $validation = array(
      array('field' => 'startDate', 'label' => 'StartDate', 'rules' => 'required|callback_compareDate'),
      array('field' => 'endDate', 'label' => 'endDate', 'rules' => 'required|callback_compareDate'),
    );
    

    Then load CI validation library as,

    $this->form_validation->set_rules($validation);
    $this->form_validation->set_message('required', '%s is required.');
    

    This is the called back function.

    function compareDate() {
      $startDate = strtotime($_POST['startDate']);
      $endDate = strtotime($_POST['endDate']);
    
      if ($endDate >= $startDate)
        return True;
      else {
        $this->form_validation->set_message('compareDate', '%s should be greater than Contract Start Date.');
        return False;
      }
    }
    

    The “required” validation makes the fields mandatory to be filled with something.
    The callback function, in this case, compares the dates, and further processes the form if start date is less than from date OR flags error otherwise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to validate 2 date input in codeigniter, with the conditions, if the
i saw this example : Validate that end date is greater than start date
I'm trying to use javascript regex to validate a date input, but it is
I am trying to validate input date fields, and I want to make sure
I want to validate user input on a Web Form, like valid numbers, date
I want to validate a phone number input. The phone numbers should be mix
I want to validate a form fields (text) input. It should only be a
I have a input field and on clicking that I will show a date
i want my code to validate date according to format , day month aslo
I have a Java EE application and I want to validate a Date. With

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.