skip to Main Content

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>

3

Answers


  1. This way:

    <input type="date" id="date_from" name="date_from" value="<?php echo isset($_POST['date_from'] ? $_POST['date_from'] : '' ?>">
    
    Login or Signup to reply.
  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'] : '' ?>';
    
    Login or Signup to reply.
  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"));
    }); 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search