Resending $_POST Without a Form?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Zzarkc-20
Forum Newbie
Posts: 13
Joined: Tue Jul 29, 2008 2:09 am
Location: Indiana

Resending $_POST Without a Form?

Post by Zzarkc-20 »

I'm not sure this is the right forum to post this question, but I'm curious to know if there's a way to resend $_POST to another page. Say you have a form that sends the data via $_POST to itself. There you can check the form, and then display the information if it is all correct, and let them check it one last time. Is there then an easy way to send the $_POST with all the information in it to another page to process it (like send an email to the user, server processing, etc.) I can think of a lengthy way involving recreating another form, hiding all the elements, and adding the values from the previous form into new variables. That seems a bit tasking to me, so I'm curious if there is a more concise method. Thanks!
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Resending $_POST Without a Form?

Post by allspiritseve »

Could you maybe have a hidden field that lets the script know whether to display the form for verification, or process it? Then you could check for it like this:

Code: Select all

 
if ($_POST['hidden_field'] = 'verify'):
// Display for verification
elseif ($_POST['hidden_field'] = 'process'):
// Process
else:
// Display form
endif;
Zzarkc-20
Forum Newbie
Posts: 13
Joined: Tue Jul 29, 2008 2:09 am
Location: Indiana

Re: Resending $_POST Without a Form?

Post by Zzarkc-20 »

I suppose that would get the job done as well. It doesn't really get the $_POST off the page and too another one without a form though.

I suppose this could be a good reason to use $_GET instead. You could just append the URL with the variables that way and send it to the new page (that they could bookmark). If I went that route I would need a good way to change the variables from $_POST to $_GET.

Also, with the form displaying it's content (information is already entered), is it safe to use a simple back button (using Javascript and histories) to navigate the person back to the page to change information?
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Resending $_POST Without a Form?

Post by allspiritseve »

If you are set on processing in a different script, then maybe you could make the intermediate page (verify form input) a new script. That way, form (1) posts to verify (2), which posts to process (3).
Zzarkc-20
Forum Newbie
Posts: 13
Joined: Tue Jul 29, 2008 2:09 am
Location: Indiana

Re: Resending $_POST Without a Form?

Post by Zzarkc-20 »

Right. That's kind of the idea I want to get too, but I can't figure out the way to get the $_POST to be sent again from the verify stage to the processing stage. I'm probably being ignorant, but from the book I'm learning from, it says nothing about resending $_POST without a form.
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Resending $_POST Without a Form?

Post by allspiritseve »

I know you're not displaying the form again, but you are essentially submitting form information if you display information for verification and ask the user to click "submit". The solution to this is to place the form data in hidden fields, and have the form post to the process page. The only visible part of the form will be the submit button.
Post Reply