• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Newbie PHP Question

TeamZero

Senior member
Is it possible to pass POST variables (declare a new one and pass it) to another page, without submitting a form?

The only way I know how to assign values to the $_POST array is by submitting a form with named inputs. Is there another way to do it?
 
So instead of a submit button, the user is just clicking a link? If so, you can use javascript to submit hidden form elements. Not exactly sure how to do it, but I know it's really easy.

Just reread your post. I'm not sure if you would consider this submitting a form.

This could possibly work:

$_POST['myvar'] = "astring";

Then on the next page:

$myvar = $_POST['myvar'];

That seems too simple though, so it doesn't seem like it would work.
 
Originally posted by: txrandom
Actually it would just be easier to use sessions:

sessions are great...until you have to scale your site into multiple servers :

TZ, do they have to be POST?
You can redirect to a url with the variables as url params (GET).

If they need to be POST, you can output the variables as hidden fields in a hidden form and autosubmit it with javascript (but its not the best practice)
 
I understand GET varisbles as well.

It seems like it would be best to just use multiple sessions, since the only way to do it is submit hidden fields.

Thanks guys.

Edit: spelling
 
The very nature of the POST method requires a form POST. End of story.

If you want, you can use javascript to make a link submit a form, or use javascript to auto-submit a form when a page loads.
 
Back
Top