"Bela" <alebtele2.it> wrote in message
news:a0daa249.0307150322.51280175posting.google.c om...
> In my site users fill a page ("questionaire") and they view their
> result in ("result") page. (I use POST method )
>
> Now I want replace the "questionaire" page with a csv file uploaded.
> I upload my csv file and I read it without problem (thx Zac). Have you
> an idea how to go (with method POST) to my "result" page ?
Hello again, Bela,

If you don't want to just display the results to the user using the same
script that recorded the results (which is pretty easy), you'll have to take
advantage of a few tricks involving the user's browser.

First, the POST method may not be the most effective way to do this.
Consider using the GET method, Cookies, or PHP sessions before going ahead
with this method. These methods are more simple to use and takes more
burden off of the client and puts it on the server.

I'm sorry if you already know this, but for a POST, GET, or PUT transaction
to occur, the client (your visitor's browser) has to create the request and
send it to the server via HTTP. Using the GET method is easy since you can
send a response header to the client asking it to request a specific page
from the server. In that header, you can include tons of query information
in the URL just like a URL in a hyperlink.

Using the POST method is similar to the GET method except that you don't use
the URL to send the query. The POST query is contained in the request's
header. For security reasons, a web server can not "force" a client to send
a specific request header. However, you can give the browser the necessary
information to "build" the correct POST request and have it send the request
automatically.

I've done this two different ways:

1. You can have your PHP script that ps your questionaire results send
an invisible HTML form to the client. To make a form "invisible," just make
a bunch of type="hidden" form tags and set names/values to what you want to
pick up in your "results" page. You'll need to be careful about quotation
marks when doing this. If a stray quotation mark "breaks" any of your
value="something" fields, your form will be useless. It's a good thing PHP
has some nice quotation mark stripping functions.

To have the form submit itself when it's finished, create a page like this:

<html><head></head><body onload="doent.forms[0].submit();">
<form method="post" action="resultspage.php">
<!-- hidden input fields generated by PHP script... -->
<input type="hidden" name="key1" value="Data." />
<input type="hidden" name="key2" value="More Data." />
</form>
</body></html>

2. A somewhat "safer" way to build a form, that's not necessarily as
browser friendly, is to send an empty HTML form to the client and add all
the form data through JavaScript. The reason I say "safer" is because you
can escape your quotation marks in JavaScript strings easier than in HTML
attributes:

<html><head>
<script type="text/javascript">
function submit_form() {
myform = doent.forms[0];
myform.key1.value = "Data.";
myform.key2.value = "More Data.";
myform.key3.value = "Even \"More\" Data.";
myform.submit();
}
</script>
</head><body onload="submit_form();">
<form method="post" action="resultspage.php"></form>
</body></html>

I used to use these methods for about the same purpose you are using them.
However, as soon as you get passed the initial learning curve of PHP
sessions, they are in many aspects superior to these techniques. I would
say that if you have fewer than 10 fields of data, the GET method is easier,
quicker, and doesn't suffer from issues with browser incompatibilites. If
you have 10 to 30 fields of data, I would stick with PHP sessions. They're
easy to use and have very little reliance on the client's capabilities. If
you have more than 50 fields of data, it's time to start loading the data
into a database and sending record keys through GET queries or Cookies
(sessions work well here, too) that reference the data.

Hope this helps.

Caio,
Zac