views:

84

answers:

5

Edit: I could simplify this question by asking is there a way to do something like header('Location: /msg_form.php?error=3') except sending error=3 and all the other form info via POST. I think the short answer is no, but there are alternative ways to do things.


I integrated a message system into my website which used GET for everything but I needed to send messages to large lists of people so I had to switch to using POST. However that screws up the system when you submit the message form and there are errors. The form submits to a processing page and if there are errors it is supposed to redirect back to a form page but now that dumps all the POST info. :(

Isn't there some way for me to simulate a form submission from the php processing page? I would think that curl could do this for me but so far it seems to just send POSTS out to the netherworld but not actually redirect the browser.

I guess I could have it print out a form with some hidden variables and then redirect with html or javascript but that seems dumb. Also I could integrate the processor right into the form page, which I might do, but I'd rather not re-arrange to much stuff.

+4  A: 

Often, I will use the same page for form entry and form processing. At the top of the page, you check for the POST variables, and process accordingly. I build a string with any errors. Then at the end of the processing code, if there are errors, re-display the entry page with the errors. Otherwise, redirect or display a thank you page, etc.

You could also use jQuery, to submit the form while staying on the page, and process the response (display the errors that come back, or redirect).. There are many ways to solve your issue.

Fosco
+3  A: 

well.. i'm not sure what you're trying to do.. but if you need to send POST from php you can do it with curl with something like this:

<?php
 $ch = curl_init('http://mysite.com/index.php');
 curl_setopt ($ch, CURLOPT_POST, 1);
 curl_setopt ($ch, CURLOPT_POSTFIELDS, "option=com_content&task=blogcategory&id=24&Itemid=55");
 curl_exec ($ch);
 curl_close ($ch);
?>
pleasedontbelong
But this doesn't redirect the browser, it just hangs on the processing page for me.
Moss
that's because curl is not used for redirecting, what it does is call url and prints out the result, anyway.. if you need to use curl to call a page within your site, i'd say that you have a design problem there, you might want to use another approach. Usually when there was an error on the form, the processing page will not redirect the browser but recreate the form using the $_POST to fill the form and indicate the errors found.
pleasedontbelong
Is curl supposed to print out the results from the page that it calls like echo, and like an AJAX call? Because all I get is a blank page.
Moss
yes.. it prints out the result but you could also save it into a variable. http://fr2.php.net/manual/en/curl.examples-basic.php, if it doesnt do anything, well.. pff.. try to do a simple call (to a "hello world" page for exemple) to test if the problem is in your code
pleasedontbelong
A: 

You could use sessions, a service provided by the server that uses the cookies. Or you could send your info with the http transmission (longer solution)...

Charlie
What do you mean about http transmission? Or is that some unpractical thing?
Moss
POST data are sent in a different way from GET. Look here (http://developers.sun.com/mobility/midp/ttips/HTTPPost/)Theoretically if you don't want to use forms you php code could send the POST data writing them in the HTTP communication.
Charlie
+2  A: 

You could keep the POST data in session variables.

Erik B
A: 

You could keep the POST data in a cookie.

Erik B