PDA

View Full Version : post form autmagically


brothercake
09-17-2002, 01:34 PM
I'm sure this has been asked before; but I can't find it if it has:

What I'd like to do is post form data from php; so script receives user-posted data and compiles it such that:

$info["value name"] = "first value";
$info["value name"] = "second value";

etc. How could I assemble that data and POST it back to another page without further user intervention?

Dylan Leblanc
09-17-2002, 11:13 PM
< input type="text" name="info[name]" size="20" >

would give you a variable $info['name'] in your PHP script, or $_POST['info']['name']

craigh@mac.com
09-17-2002, 11:43 PM
or you can use hidden form elements with the same type of results. You can also include the VALUE="$myvalue" Tag in either of those.

brothercake
09-17-2002, 11:48 PM
Thanks; I understand that. What I'd like to know is how to POST that form without user intervention.

Dylan Leblanc
09-17-2002, 11:54 PM
You mean be able to POST data without the user using an actual form?

Either you could use all hidden input types and have the user click on a submit button, or do something tricky like Google.com does on their main page. They have a hidden form, and when someone click on a link on the page, it is actually routed though that form using Javascript.

craigh@mac.com
09-18-2002, 12:00 AM
couldn't you do an onLoad handler to submit the form too? course then your page would either reload or disappear. Why exactly are you trying to do this?

brothercake
09-18-2002, 10:19 AM
What it's for is a mailform - you fill in the form and the PHP script validates it; if any fields are found empty is sends you back to the same page, with the unfilled fields marked in red.

But obviously to do this, it's necessary also to pass back all the data which a user has already filled in - ie, the POST data has to be sent back to the form page.

So that's what I want to do. The POST data is processed by the PHP script, recompiled and then sent back to the origin form, so I need a way of posting without user intervention.

Using onload to submit the form is what I'm doing at the moment. But it won't really do - javascript support cannot be relied on.

craigh@mac.com
09-18-2002, 01:41 PM
how about using sessions instead or you could use the GET method instead of POST.

brothercake
09-18-2002, 02:20 PM
GET is not appropriate - too much data.

Can you elaborate on "use sessions" - you mean store the info in a DB?

mordred
09-18-2002, 02:30 PM
Not necessarily, just create a session variable that contains the array of the $_POST data:

$_SESSION["lastPostData"] = $_POST;

There are though some things to take care of if you intend to use sessions; since there were some changes and some quirky behaviour during the last PHP releases, you should have a look at what the manual says about session usage.

Galdo
09-18-2002, 07:52 PM
Why not just have it all on the same page and have the form submit to itself?

brothercake
09-19-2002, 01:37 AM
Originally posted by Galdo
Why not just have it all on the same page and have the form submit to itself?

Well yes, that would be best. But it's not possible because the mail script is on a different domain .... it's a long story :rolleyes:

I guess the session idea is the best .. but is that still gonna work between two domains?

mordred
09-19-2002, 02:00 AM
I'm sort of confused concerning the program execution flow of your application. Am I right that you have one PHP page that takes POST data and reassembles the form while another PHP page sends the validated data as a mail?
And both pages are located on different domains on different servers?

brothercake
09-19-2002, 02:40 AM
You're confused ... imagine how I feel :o

Anyway, it's like this:

Page A: a form page on domain 1 [which posts to] Page B: a script on domain 2 [which sends an email and then posts some of the data to] Page C: a "thank you" page back on domain 1


Why is the script on domain 2? Well, because the sendmail module on domain 1's web server (where the site is) doesn;t work properly. Until it's fixed, I need an interim solution, which is to hotlink to mail script from domain 2 (my personal site). It needs to post data back to domain 1 simply so that's where the page is - back on the company site. A user will probably not even notice.

It's all very convoluted I know ... but this is how it is.

firepages
09-19-2002, 03:00 AM
get snoopy (http://snoopy.sourceforge.net) and make like a browser ;)

mordred
09-19-2002, 01:49 PM
If I understand this correctly, your problem is that you submit data to script on a different server which shall send the user back to the original site, located on the first server, and with the POST data included that may be needed for error messages and such.

One thing I suppose you want to prevent is that the domain in the address bar of the user's browser changes and displays your site's URL, so simply including a remote file on your server rules out.

An alternative to firepages suggestion (which is, as far as what I've heard about snoopys possiblities, a very good one) would be to make use of the cURL extension. With that you could send also a POST request from within another script and fetch the result. For more details, see http://www.php.net/manual/en/ref.curl.php .
It need to be enabled on that host though, since it's not a standard extension.

brothercake
09-20-2002, 12:04 AM
I reckon that Snoopy thing will show me the way; I should be able to extrapolate the method from that.

Thanks all for your help :thumbsup: