'Keep the date value in a html form after it has been submitted

I have created this form which I have placed in the Wordpress divi theme code module on a page. It is used to return the stock availability for my shop that is connected to a 3rd party api.

After the form is submitted how do I get it to keep displaying the values that were submitted.

<p>Enter your Event Dates</p><br>

<form class="Dates" action="" method="post">

<span>
  <label for="date_from">Date From:</label>
  <input type="date" id="date_from" name="date_from" value="dd-MM-YYY">
</span>

<span>
  <label for="date_to">Date To:</label>
  <input type="date" id="date_to" name="date_to" value="dd_MM-YYY"><br>
</span>

<input type="submit">
</form>


Solution 1:[1]

This way:

<input type="date" id="date_from" name="date_from" value="<?php echo isset($_POST['date_from'] ? $_POST['date_from'] : '' ?>">

Solution 2:[2]

You can try writing a new script under all javascript definitions. Page must .php

<script>
document.getElementById("date_from").value = '<?php echo isset($_POST['date_from'] ? $_POST['date_from'] : '' ?>';

Solution 3:[3]

If you want to use jquery you should use this format:

$(function(){
 $('#date_from').val('submitted value');
}); 

but jquery doesn't know what was sent before. So you can update your script like this:

$(function(){
 $('#date_from').on("keyup",function(){
    window.localStorage.setItem('date',$(this).val());
 });

 $('#date_from').val(window.localStorage.getItem("date"));
}); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tayfun Yuksel
Solution 2 Tayfun Yuksel
Solution 3 Tayfun Yuksel