Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-11 16:18:30

jcamenisch
New Member
From: Oklahoma City
Registered: 2005-03-19
Posts: 9
Website

How to access $_POST from within article <txp:php></txp:php>

Is there any way to access posted form fields from within a Textpattern article? The $_POST array seems to be emptied by the time my embedded PHP runs.

I haven’t tried using GET yet, which might be acceptable, I guess.

Last edited by jcamenisch (2006-01-11 16:19:38)


Jonathan Camenisch

Offline

#2 2006-01-11 16:24:13

jcamenisch
New Member
From: Oklahoma City
Registered: 2005-03-19
Posts: 9
Website

Re: How to access $_POST from within article <txp:php></txp:php>

Update: GET doesn’t work either (naturally).


Jonathan Camenisch

Offline

#3 2006-01-11 16:26:44

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: How to access $_POST from within article <txp:php></txp:php>

The $_POST array seems to be emptied by the time my embedded PHP runs.

No, nothing like that happens. Maybe there’s a http-redirect involved and that’s why you find _POST to be empty. But nobody can tell, without knowing what exactly it is you are trying to do.

(Yes, you would access $_POST the same way you would otherwise. Though you may find it even simpler to use txp’s own functions, like ps(), gps() etc.).

Offline

#4 2006-01-11 16:32:49

jcamenisch
New Member
From: Oklahoma City
Registered: 2005-03-19
Posts: 9
Website

Re: How to access $_POST from within article <txp:php></txp:php>

Hmm. As far as redirects, no, there’s nothing of the kind that I know of. It’s just a standard Textpattern install. The url in the browser’s address bar doesn’t change, and the whole page is rendered directly by Textpattern. (Is there some sort of redirect I’m not thinking of?)

I put the following into an article named “post-get-test” in section “lists”:

<code>
<txp:php> echo “It’s running”; echo implode(‘;’,$_GET);
</txp:php>
</code>

When I go to http://cherifuller.gospelcom.net/lists/post-get-test?test1=this&test2=that, I would expect to see “It’s runningthis;that,” or something like that. All I get is “It’s running.”

Thanks for the quick answer.

Last edited by jcamenisch (2006-01-11 19:16:24)


Jonathan Camenisch

Offline

#5 2006-01-11 16:42:31

jcamenisch
New Member
From: Oklahoma City
Registered: 2005-03-19
Posts: 9
Website

Re: How to access $_POST from within article <txp:php></txp:php>

Then again, I just tried the same thing on a different Textpattern site, and it works. So it must be something about this particular site’s setup. Bum. Well, back to work…


Jonathan Camenisch

Offline

#6 2006-01-11 22:10:38

jcamenisch
New Member
From: Oklahoma City
Registered: 2005-03-19
Posts: 9
Website

Re: How to access $_POST from within article <txp:php></txp:php>

I finally found out what the problem was. This site was set up on a host that will not let me edit .htaccess, so textpattern is running as a 404 document. When I emulate that on my computer, it doesn’t work, but when I switch it to using the standard .htaccess file, it works fine.

If anyone has ideas for a workaround on this, I would love to hear them. Unfortunately, I’m kinda stuck with this hosting situation for now.


Jonathan Camenisch

Offline

#7 2006-01-11 22:17:39

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: How to access $_POST from within article <txp:php></txp:php>

This site was set up on a host that will not let me edit .htaccess, so textpattern is running as a 404 document.

I think you’ll find that’s the culprit. Some servers don’t pass GET and POST correctly to error handler documents. I don’t know of a fix, just workarounds:

  • Always use index.php as the action URL in POST forms
  • You could probably rebuild $_GET using $_SERVER[], parse_url() and parse_str()

Alex

Offline

#8 2006-01-11 23:11:42

jcamenisch
New Member
From: Oklahoma City
Registered: 2005-03-19
Posts: 9
Website

Re: How to access $_POST from within article <txp:php></txp:php>

Yes, I was able to set up the GET fields by placing the following in index.php before the textpattern code:

<html><pre>
if ($_SERVER[‘REDIRECT_QUERY_STRING’]) { $pairs = split(‘&’, $_SERVER[‘REDIRECT_QUERY_STRING’]); foreach ($pairs as $pair) { $pair = split(‘=’, $pair); $_GET[$pair0] = $pair1; }
}
</pre></html>

This way, on each page (or whatever), I can code as though I’m on a normal server. Apparently, though, Apache does not pass POST fields to 404 handlers, so that information is just not accessible.

Thanks always.


Jonathan Camenisch

Offline

#9 2006-01-11 23:22:13

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: How to access $_POST from within article <txp:php></txp:php>

I finally found out what the problem was. This site was set up on a host that will not let me edit .htaccess, so textpattern is running as a 404 document. When I emulate that on my computer, it doesn’t work, but when I switch it to using the standard .htaccess file, it works fine.

Don’t know if you did a home-cooked version of running Textpattern as 404 document, or if you followed my instructions here http://textpattern.com/weblog/135/partly-messy-clean-urls-without-modrewrite-experimental. In that article I specifically make mention of that problem in connection with Apache webservers (lighttpd for example doesn’t have the problem) and why there’s the workaround to use messy urls only during commenting for that exact reason.

Offline

Board footer

Powered by FluxBB