I have a huge form with inputs of type (text, checkboxes, hidden et). The content of the form inputs are taken from a database. The user has to make some changes and to save the data back into the db.
At this moment I'm using a function which has a foreach($_POST as $key=>$value)
loop. As you know, there are problems with post method:
- can't make refresh,
- can't go backwards.
I'll like to use $_GET
method, but the length of my variables and values are bigger than 2000 characters.
Do you have any advice for me, about what can I do? Maybe there are some tricks in using $_GET
. Maybe i didn't understand how to use it right?
As far as loop processing goes, the foreach loop contruct in PHP makes a copy of the array you are working on. If you want to process $_POST with a different loop construct (for / while) and use functions like count(), current(), reset(), next(), prev(), end(), each(), or key(), have at it.
Programming PHP: Chapter 5, p. 128-129
Use the Post/Redirect/Get pattern.
There is absolutely nothing wrong in POST itself. You just have to use it properly
An HTTP standard says you ought to make a GET redirect after receiving POST request.
So, as easy code as this
after processing your form will solve all your "problems"
in case you want to handle post errors, you can use POST/Redirect/GET pattern. However it does not redirect on error, the problems you mentioned becoming negligible.
here is a concise example of it:
on error it will show the form back. but after successful form submit it will redirect as well.