I am trying to find what the easiest way to keep form values after post. I am really trying to have to keep from learning ajax right this second for the one form, Plus I am not sure how hard it would be to implement ajax into my already existing google map page. So I am trying to find a way to retain the values of two date fields after submit has been pushed
When you refresh you cannot use react state or redux store as they are cleared and initialized with each page refresh. The best approach I see here is to use your localstorage to store the values. Then you can check whether the data is available in localstorage and use that on the initial render using a useEffect hook.
To keep the values, you must fill in the values on the server while rendering the page. Usually, you can simply copy the data from the HTML request parameters into the fields.
you can save them into a $_SESSION variable and then when the user calls that page again populate all the inputs with their respective session variables. storing them into a $_SESSION would kill the server. cookies or the chosen answer are the best ways. @zeeks I'm a beginner in php.
If you are looking to just repopulate the fields with the values that were posted in them, then just echo the post value back into the field, like so:
<input type="text" name="myField1" value="<?php echo isset($_POST['myField1']) ? $_POST['myField1'] : '' ?>" />
you can save them into a $_SESSION variable and then when the user calls that page again populate all the inputs with their respective session variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With