0

I want to restrict date input in my form. I'm using PHP and HTML to code.

<?php
echo '<input type="date" name="doc" value="' . date("d-m-Y") . '" min="11-05-2014" max="' . date("d-m-Y") . '"/>';
?>

I've tried this post. It has a solution using jQuery, but I don't want to use jQuery.

nirupma
  • 85
  • 1
  • 8
  • Change your date format to `date("Y-m-d")` – Ryan Jun 04 '18 at 07:25
  • Thanks a lot Ryan! – nirupma Jun 04 '18 at 07:27
  • 1
    if you want some checking server side (which is important btw), just process the form like you normally do, get the input, convert it to unix time stamp and compare it to `time()`, a simple `if` should suffice, the rest of the business logic is up to you – Kevin Jun 04 '18 at 07:28
  • Thanks Ghost! I've added the check as you suggested. – nirupma Jun 04 '18 at 07:29
  • You can of course reject the chosen date once its been submitted to server—but there's no way to prevent user from choosing it in the first place. PHP is a server-side technology, it doesn't even run on the same computer as the HTML code. – Álvaro González Jun 04 '18 at 08:31

1 Answers1

0
 <?php
echo '<input type="date" name="doc" value="' . date("Y-m-d") . '" min="2014-11-04" max="' . date("Y-m-d") . '"/>';
?>
Sachin
  • 397
  • 4
  • 13
  • Please don't make other users look into your code to see what you changed. Add a clear description of what you changed to write a complete answer. – Jesse Jun 04 '18 at 09:05