By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,466 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,466 IT Pros & Developers. It's quick & easy.

Code problem: Form will only work under GET method

P: n/a
This has ocurred before, but if the person had find a way to solve it
or not, I've got no clue. So, here I am to ask for help.

I've created a form via pure PHP, basically a bunch of prints together
making a form. But somthing strange goes on: the form will only pass
it's fields forward under method GET, but not on POST.

Here's a snippet of code, just the basics:

print "<form name=\"postcomment\" action=\"".HTTP_ROOT."/pages/
comment.php\" method=\"POST\">\n";
print "Nome:<br/><input type=\"text\" name=\"nome\" size=\"64\" /><br /
>";
print "Email(obrigatório; não será publicado):<br/><input type=\"text
\" name=\"email\" size=\"64\" /><br />";
print "Site:<br/><input type=\"text\" name=\"url\" size=\"64\" /><br /
>";
(...)
print "</form>\n";

This is the code that creates the form. The target page has this code
in it:

//print_pre is a function that prints "<pre>".print_r(var,true)."</
pre>", for debugging
print_pre($_POST);
print_pre($_GET);
print_pre($_REQUEST);

When method is POST, here's what I get:

Array
(
)
Array
(
)
Array
(
)

But when method is GET, this comes instead:

Array
(
)
Array
(
[nome] =Bruno Guedes
[email] =bruno_guedesav%40yahoo.com.br
[url] =about%3Ablank
(...) //There are more fields, but they aren't important
)
Array
(
[nome] =Bruno Guedes
[email] =bruno_guedesav%40yahoo.com.br
[url] =about%3Ablank
(...) //Again, there *are* mroe fields, but they don't matter
[PHPSESSID] =09772a2105568a91612fdd33d49d8212
)

So, sorry for the long post, but what's the big deal, anybody knows?
Nov 19 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Mon, 19 Nov 2007 19:29:38 +0100, bruno_guedesav
<br************@yahoo.com.brwrote:
This has ocurred before, but if the person had find a way to solve it
or not, I've got no clue. So, here I am to ask for help.

I've created a form via pure PHP, basically a bunch of prints together
making a form. But somthing strange goes on: the form will only pass
it's fields forward under method GET, but not on POST.

Here's a snippet of code, just the basics:

print "<form name=\"postcomment\" action=\"".HTTP_ROOT."/pages/
comment.php\" method=\"POST\">\n";
print "Nome:<br/><input type=\"text\" name=\"nome\" size=\"64\" /><br /
>";
print "Email(obrigatório; não será publicado):<br/><input type=\"text
\" name=\"email\" size=\"64\" /><br />";
print "Site:<br/><input type=\"text\" name=\"url\" size=\"64\" /><br /
>";
(...)
print "</form>\n";
I'm not going to check that quote-escape festival just yet. Try to
validate the page it creates with the w3c HTML validator, most likely you
error will show up there.

If after that it still doesn't work/there are no errors, what form does
your code actually output, and how does your webserver log the request?
--
Rik Wasmus
Nov 19 '07 #2

P: n/a
bruno_guedesav wrote:
I've created a form via pure PHP, basically a bunch of prints together
making a form. But somthing strange goes on: the form will only pass
it's fields forward under method GET, but not on POST.
Has your server been able to accept other POST forms OK -- is it just
this one that's causing problems?

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 13 days, 16:40.]

USD/EUR Exchange Rate Graph
http://tobyinkster.co.uk/blog/2007/11/18/usd-eur/
Nov 20 '07 #3

P: n/a
On 20 nov, 07:44, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
bruno_guedesav wrote:
I've created a form via pure PHP, basically a bunch of prints together
making a form. But somthing strange goes on: the form will only pass
it's fields forward under method GET, but not on POST.

Has your server been able to accept other POST forms OK -- is it just
this one that's causing problems?
There's another form that goes fine on POST, and it has the same
inputs: text, checkbox, and textarea.
Nov 20 '07 #4

P: n/a
On 19 nov, 16:38, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Mon, 19 Nov 2007 19:29:38 +0100, bruno_guedesav

<bruno_guede...@yahoo.com.brwrote:
This has ocurred before, but if the person had find a way to solve it
or not, I've got no clue. So, here I am to ask for help.
I've created a form via pure PHP, basically a bunch of prints together
making a form. But somthing strange goes on: the form will only pass
it's fields forward under method GET, but not on POST.
Here's a snippet of code, just the basics:
print "<form name=\"postcomment\" action=\"".HTTP_ROOT."/pages/
comment.php\" method=\"POST\">\n";
print "Nome:<br/><input type=\"text\" name=\"nome\" size=\"64\" /><br /
";
print "Email(obrigatório; não será publicado):<br/><input type=\"text
\" name=\"email\" size=\"64\" /><br />";
print "Site:<br/><input type=\"text\" name=\"url\" size=\"64\" /><br /
";
(...)
print "</form>\n";

I'm not going to check that quote-escape festival just yet. Try to
validate the page it creates with the w3c HTML validator, most likely you
error will show up there.

If after that it still doesn't work/there are no errors, what form does
your code actually output, and how does your webserver log the request?
The HTML validator goes fussy on some input tag it claims it's closed
but not opened, when it clearily is. Here's the HTML output of the
form:

<form name="postcomment" action="http://www.dcc.ufmg.br/~guedesav/
PbBlog/pages/comment.php" method="POST">
<p class="disclaimer">AVISO: seu comentário pode ser enviado para
moderação caso:<br/>
a) não contenha um nome de autor;<br/>
b) contenha material impróprio;<br/>
c) seja, possivelmente, spam;<br/>
Caso seu comentário não seja spam, mas sim um comentário legítimo,
aguarde algumas horas e a justiça será feita. Obrigado pela
paciência.</p>Nome:<br/><input type="text" name="nome" size="64" /
><br />Email(obrigatório; não será publicado):<br/><input type="text"
name="email" size="64" /><br />Site:<br/><input type="text" name="url"
size="64" /><br /><p>Comentário:<br /><textarea cols="56" rows="8"
name="content"></textarea></p><input type="checkbox"
name="notify">Notificar respostas a comentário</input><br/>
<p class="captcha">Responda a esta simples pergunta:
<img style="display: block; text-align: center" src="http://
www.dcc.ufmg.br/~guedesav/PbBlog/img/captcha225896485.png" />

<input type="text" name="captcha-answer" size="16" />
<input type="hidden" name="captcha-key"
value="*908BE2B7EB7D7567F7FF98716850F59BA69AA9DB" />
</p>
<br /><input type="submit" value="Enviar Comentário" />
</form>

Besides, as I said, the form works finely in GET method, but not in
POST. If it goes fine with GET, how come the problem is with the
syntax?
Nov 20 '07 #5

P: n/a
On Tue, 20 Nov 2007 12:04:17 +0100, bruno_guedesav
<br************@yahoo.com.brwrote:
On 19 nov, 16:38, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>On Mon, 19 Nov 2007 19:29:38 +0100, bruno_guedesav
<bruno_guede...@yahoo.com.brwrote:
This has ocurred before, but if the person had find a way to solve it
or not, I've got no clue. So, here I am to ask for help.
I've created a form via pure PHP, basically a bunch of prints together
making a form. But somthing strange goes on: the form will only pass
it's fields forward under method GET, but not on POST.
Here's a snippet of code, just the basics:

I'm not going to check that quote-escape festival just yet. Try to
validate the page it creates with the w3c HTML validator, most likely
you
error will show up there.

If after that it still doesn't work/there are no errors, what form does
your code actually output, and how does your webserver log the request?

The HTML validator goes fussy on some input tag it claims it's closed
but not opened, when it clearily is. Here's the HTML output of the
form:
I hate to play validator, I distilled the location of the online form
though, so let's have a go at submitting the form:

HTTP/1.x 302 Found
Date: Tue, 20 Nov 2007 17:55:05 GMT
Server: Apache/2.0.59 (FreeBSD) mod_ssl/2.0.59 OpenSSL/0.9.7e PHP/5.1.4
Location:
http://homepages.dcc.ufmg.br/~guedes...me=etc.etc.etc.
Content-Length: 561
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

Your site is not at <http://www.dcc.ufmg.br/~guedesav/PbBlog/>, it's at
<http://homepages.dcc.ufmg.br/~guedesav/PbBlog/>, and as the server is set
up to do an external redirect, and browsers will NOT post to the 'new'
page they're redirected to, they'll perform a GET, and POST values will be
lost.

Either:
- use the proper host in the url in your form (http://homepages...),
- use a relative url (action="./pages/comment.php" or
action="/~guedesav/PbBlog/pages/comment.php"),
- or configure the server to do this kind of redirects internally instead
of external.

While the (X)HTML was not the problem it is really in need of cleaning up.
Not a PHP issue though. (</inputcan never, ever exist in current (X)HTML
for instance).
--
Rik Wasmus
Nov 20 '07 #6

P: n/a
On 20 nov, 16:04, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Tue, 20 Nov 2007 12:04:17 +0100, bruno_guedesav

<bruno_guede...@yahoo.com.brwrote:
On 19 nov, 16:38, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Mon, 19 Nov 2007 19:29:38 +0100, bruno_guedesav
<bruno_guede...@yahoo.com.brwrote:
This has ocurred before, but if the person had find a way to solve it
or not, I've got no clue. So, here I am to ask for help.
I've created a form via pure PHP, basically a bunch of prints together
making a form. But somthing strange goes on: the form willonlypass
it's fields forward under methodGET, but not on POST.
Here's a snippet of code, just the basics:
I'm not going to check that quote-escape festival just yet. Try to
validate the page it creates with the w3c HTML validator, most likely
you
error will show up there.
If after that it still doesn'twork/there are no errors, what form does
your code actually output, and how does your webserver log the request?
The HTML validator goes fussy on some input tag it claims it's closed
but not opened, when it clearily is. Here's the HTML output of the
form:

I hate to play validator, I distilled the location of the online form
though, so let's have a go at submitting the form:

HTTP/1.x 302 Found
Date: Tue, 20 Nov 2007 17:55:05 GMT
Server: Apache/2.0.59 (FreeBSD) mod_ssl/2.0.59 OpenSSL/0.9.7e PHP/5.1.4
Location: http://homepages.dcc.ufmg.br/~guedes...ment.php?nome=....
Content-Length: 561
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

Your site is not at <http://www.dcc.ufmg.br/~guedesav/PbBlog/>, it's at
<http://homepages.dcc.ufmg.br/~guedesav/PbBlog/>, and as the server is set
up to do an external redirect, and browsers will NOT post to the 'new'
page they're redirected to, they'll perform aGET, and POST values will be
lost.

Either:
- use the proper host in the url in your form (http://homepages...),
- use a relative url (action="./pages/comment.php" or
action="/~guedesav/PbBlog/pages/comment.php"),
- or configure the server to do this kind of redirects internally instead
of external.

While the (X)HTML was not the problem it is really in need of cleaning up.
Not a PHP issue though. (</inputcan never, ever exist in current (X)HTML
for instance).
--
Rik Wasmus
Oh, right, this makes sense, now. Thank you very much for the help,
I'll redefine the address constant, then. Thanks again!
Nov 20 '07 #7

P: n/a
Rik Wasmus:
(</inputcan never, ever exist in current (X)HTML for instance).
Never say never. </inputcan occur as an end-tag in XHTML, but for
compatibility there is an RFC "should" in its way.

--
Jock
Nov 20 '07 #8

P: n/a
On Nov 20, 9:04 pm, bruno_guedesav <bruno_guede...@yahoo.com.br>
wrote:
On 19 nov, 16:38, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Mon, 19 Nov 2007 19:29:38 +0100, bruno_guedesav
<bruno_guede...@yahoo.com.brwrote:
This has ocurred before, but if the person had find a way to solve it
or not, I've got no clue. So, here I am to ask for help.
I've created a form via pure PHP, basically a bunch of prints together
making a form. But somthing strange goes on: the form will only pass
it's fields forward under method GET, but not on POST.
Here's a snippet of code, just the basics:
print "<form name=\"postcomment\" action=\"".HTTP_ROOT."/pages/
comment.php\" method=\"POST\">\n";
print "Nome:<br/><input type=\"text\" name=\"nome\" size=\"64\" /><br /
>";
print "Email(obrigatório; não será publicado):<br/><input type=\"text
\" name=\"email\" size=\"64\" /><br />";
print "Site:<br/><input type=\"text\" name=\"url\" size=\"64\" /><br /
>";
(...)
print "</form>\n";
I'm not going to check that quote-escape festival just yet. Try to
validate the page it creates with the w3c HTML validator, most likely you
error will show up there.
If after that it still doesn't work/there are no errors, what form does
your code actually output, and how does your webserver log the request?

The HTML validator goes fussy on some input tag it claims it's closed
but not opened, when it clearily is. Here's the HTML output of the
form:

<form name="postcomment" action="http://www.dcc.ufmg.br/~guedesav/
PbBlog/pages/comment.php" method="POST">
<p class="disclaimer">AVISO: seu comentário pode ser enviado para
moderação caso:<br/>
a) não contenha um nome de autor;<br/>
b) contenha material impróprio;<br/>
c) seja, possivelmente, spam;<br/>
Caso seu comentário não seja spam, massim um comentário legítimo,
aguarde algumas horas e a justiça será feita. Obrigado pela
paciência.</p>Nome:<br/><input type="text" name="nome" size="64" /><br />Email(obrigatório; não será publicado):<br/><input type="text"

name="email" size="64" /><br />Site:<br/><input type="text" name="url"
size="64" /><br /><p>Comentário:<br /><textarea cols="56" rows="8"
name="content"></textarea></p><input type="checkbox"
name="notify">Notificar respostas a comentário</input><br/>
<p class="captcha">Responda a esta simples pergunta:
<img style="display: block; text-align: center" src="http://www.dcc.ufmg.br/~guedesav/PbBlog/img/captcha225896485.png" />

<input type="text" name="captcha-answer" size="16" />
<input type="hidden" name="captcha-key"
value="*908BE2B7EB7D7567F7FF98716850F59BA69AA9DB" />
</p>
<br /><input type="submit" value="Enviar Comentário" />
</form>

Besides, as I said, the form works finely in GET method, but not in
POST. If it goes fine with GET, how come the problem is with the
syntax?
Maybe I'm missing something here but where does this:

<p class="captcha">Responda a esta simples pergunta:

get closed? As far as I can see all your input fields are inside this
tag (in the code you posted.)

HINT: With the online validator you often need to read back a few
lines to find the real bug)
Nov 22 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.