0

I want to disable input date so that user can edit the current value in the input but i can not retrieve the value if i disable the input.

<form action="test123123.php" method="post">
<input type="date" name="datap"  value="<?php echo date('Y-m-d'); ?>" disabled>
<input type="submit" name="ok">
</form>

<?php
if(isset($_POST['ok'])){
echo $_POST['datap'];
}

This code returns the error that can not find 'datap' and i understand that it gives this error because can not see the input. How can i disable the input but be able to retrive value. The code above is just an example. I am interested on a general application not local.

Update:

i tryed with min and max in the same day but the user has to use the sliders to lock the chooce

Filip
  • 147
  • 9

2 Answers2

1

Store the known good value in a hidden field:

<form action="test123123.php" method="post">
<input type="date" name="datap-input"  value="<?php echo date('Y-m-d'); ?>" disabled>
<input type="hidden" name="datap"  value="<?php echo date('Y-m-d'); ?>">
<input type="submit" name="ok">
</form>

As others have suggested, readonly may work for you, but the behavior and appearance of disabled and readonly inputs is different. Readonly would be easier if it's appropriate for your use-case.

cdblades
  • 101
  • 2
0

Disabled element values are not passed with form submission, so use readonly instead, as:

<input type="date" name="datap"  value="<?php echo date('Y-m-d'); ?>" readonly />
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162