Short version:
- I have a form with over 100 fields and each field has server-side validation.
- I have the form working and data being submitted successfully; I'm even redirecting them back to the form when there are errors with the validation, and displaying what error in specific happened.
- When they're redirected back to the (massive) form, all of their data is gone and they need to type it again.
I have already thought of a couple ways of answering my own question, but they aren't the most elegant solutions out there.
My current thought process is: save all of their inputted data as $_SESSION variables -- and whenever they load the form, do an if
statement around each input, as such;
if(isset($_SESSION['foo_data'])) {
echo "<input type='text' name='foo' value='$_SESSION["foo_data"]'>";
} else {
echo "<input type='text' name='foo' placeholder='Enter your text here...'>";
}
This method will work, but it also involves an immensely tedious definition of 140+ session variables, followed by an even more tedious and immense creating if/else statements around EVERY form field.
Is there any better way to do this?
Additional info: using plain php, no frameworks of any kind.
if / else
statements forisset($_POST['foo_data']
to echo out different inputs, just the same as I would have to do with session variables).