Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep form values after post [duplicate]

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

like image 867
shinjuo Avatar asked Mar 04 '11 19:03

shinjuo


People also ask

How do I keep data in form after refresh in react?

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.

How do you retain the values of form after submit in JavaScript?

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.

How retain value after form submit in PHP?

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.


2 Answers

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'] : '' ?>" /> 
like image 102
Infotekka Avatar answered Oct 09 '22 03:10

Infotekka


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.

like image 25
Naftali Avatar answered Oct 09 '22 01:10

Naftali