1

Main problem is values written in input elementss disseapear after page reload (submit , refresh etc.)

I have a completed form ... /form element. Traditionally, I can insert a php line.

<input value="<?php if(isset($_POST['foo']))echo $_POST['foo'] ?>">

This solves the submit part. However, I feel that this is the worst solution, in my case. I have hundreds of input elements in my form. There are even some inputs to produce input tables. Number of input elements are so much that i became curious about finding a work around.

Is there a way to store input->values before the submit operation and inject them after page reload? So that, the user can upload a file, file will be parsed by php core. And when the page reloaded both user originated inputs and file originated values are exist.

To simplify:

After "file submit & read & append file values to form", user shouldn't need to fill inputs that s/he already filled. I need an idea to achieve this, different then "inserting a php line to every single input element."

2
  • You could use local storage (diveintohtml5.info/storage.html), but this is almost the same as PHP, just in Javascript.. Commented May 5, 2014 at 12:21
  • I looked at it for a while. "Parsing file and injecting values on local" but every article advice to not to use local sources before explaining how. Commented May 5, 2014 at 13:19

1 Answer 1

2

In such a situation I could recommend sending the file via AJAX and handling the response of that thereafter and then only injecting the values from the process and uploaded file when you get the response from the server.

Alternatively you could use localstorage or cookies to persist the information. However both local storage and cookies have a defined limit on what they can store. Cookie can only store 4KB in total which doesn't allow much.

Without uploading via AJAX, you could write a javascript function to find all inputs with jQuery/javascript and save their values in localstorage and on new page load to a check to see if there are any present and inject them back into the same inputs based on id/class/ etc with jQuery making sure to delete the localstorage values when done.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.