A form doesn't necessarily POST
the data. That would be the correct HTTP verb to use when saving data, but it's also possible to use GET
with a form. This is defined with the method
property on the form element:
<form method="post" action="I-handle-forms.php">
<!-- inputs, buttons, whatnots -->
</form>
The method you use also affects how you access the data in PHP. GET
data is available in $_GET
while POST
data is available in $_POST
. You can also use $_REQUEST
which contain both GET
and POST
data, as well as whatever cookies your site has sent.
Now as to your question about redirecting the user, you do that with header()
:
header("Location: http://example.com/thank-you.php");
But then again, it's not necessary per-se to redirect the user. It does make sense most of the time, but you could also just display your thank-yous on the page the form is submitted to.
Remember though that header()
calls must always come before anything else is sent to the browser. Even if a notice escapes from a function call before header()
the redirect wont work, so make sure to handle errors properly.
There's a nice comparison of the different verbs here. However a rule of the thumb is that GET
should be used for fetching data, like performing a search, and POST
should be used when saving data, like registration. GET
parameters are sent in the URL, so saving data from a GET
call can easily result in pointless database items.
So if I understood your situation correctly, in that users are submitting data to be saved, you should use POST
. You could have a dedicated script form-processor.php
or so to which the data is posted. Check that the data is valid, and save it to the database if it is. Then redirect the user to a thank-you page, or which ever page suits your use case. If the data is not valid, you could save the error messages to the user's session, redirect them back to the page with the form, and ask them to correct whatever mistakes were in the submitted data. If you're not using sessions, you could easily also pass the data along as GET
parameters by appending them to the redirect url:
header("Location: http://example.com/form.php?error=Invalid+email");
Remember to pass your parameters through urlencode()
first though.