32

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

Karl Adler
  • 15,780
  • 10
  • 70
  • 88
shinjuo
  • 20,498
  • 23
  • 73
  • 104
  • 4
    See: http://stackoverflow.com/questions/2246227/keep-values-selected-after-form-submission – Kevin Peno Mar 04 '11 at 19:26
  • wait are you trying to re-populate the form after a post or are you trying to reuse the values in the form after submit? like on different pages? – KJYe.Name Mar 04 '11 at 19:27
  • Do you want to just maintain access to the values? Or do you want the page to persist the values (assuming you are posting to the same page)? – Babak Naffas Mar 04 '11 at 19:28
  • I would like to either re-populate or keep the values there. I assume that to keep the values I have to use Ajax, so I would like to repopulate so the user doesnt have to remember what their selection was. – shinjuo Mar 04 '11 at 19:33
  • 1
    Shoudn't be marked as duplicate with the other question which belongs to wordpress. – Karl Adler Sep 09 '15 at 07:56

2 Answers2

72

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'] : '' ?>" />
Infotekka
  • 10,307
  • 2
  • 20
  • 17
7

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.

Naftali
  • 144,921
  • 39
  • 244
  • 303