So I'm using wordpress, but the wordpress community doesn't seem to know enough about strict PHP or anything to assist in this scenario.
I've got a plugin called Gravity Forms I'm using to create a pretty elaborate form/survey. The deal is though, it's a multi-part form and I'm not sure how to get ALL the form data from the first to the second.
I can pass data via Query String, but I'm passing 25 fields of information, so it's not quite going to work for me.
As soon as the form1 is submitted, can I then have it redirect to page two, which has some code in it like
$foo = $_POST['field_1_1'];
where field_1_1 is the name of the input from the previous form?
I've used $_GET for query strings before, but I'm not sure if the example I just stated is how to use $_POST
Yes, this is correct usage. Just make sure your form is submitting using the POST
method.
Just make sure (as you would with $_GET
) that user inputs are not to be trusted. Be sure to sanitize them for database interaction.
Yes, change your form like so:
<form method="post" action="page_to_post_to.php" name="form1" id="form1">
....
</form>
You're changing the method
to post
and the action
to a new page. The new page is that which you'll be able to access the $_POST
variables from.
If you plan to use separate forms, maybe you will find it useful to temporarily save $_POST data in session, using $_SESSION superglobal array.
Or you can just split long form with JavaScript and send it once to the final destination.
You could use $_SESSION
variable in PHP which is preserved between requests (up to however long your PHP sessions are configured -- usually a few hours)
Alternatively, you could also (somewhat inefficiently in terms of network usage) output the old form data into a <input type="hidden">
element. If you're going to do that, I'd look into using the serialize function
You may also want to look into memcache or a redis db if you're doing something in a large scale production environment
Something else you may wish to consider is using JS to do the pagination on the client side such that the form is submitted after all the pages have been filled out