Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-04-19 08:55:48

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

php on page giving errors

I have a misc form which is using custom php code and the syntax goes something like this (simplified)

<txp:php>
if ($_SERVER['REQUEST_METHOD']=="POST"){
// Email Code
} else {
</txp:php>
<form action="<txp:php> echo $_SERVER['REQUEST_URI']; </txp:php>" method="post" enctype="multipart/form-data">
// Form stuff
</form>
<txp:php>}</txp:php>

But I’m getting the error “Parse error: syntax error, unexpected $end in /home/public_html/textpattern/publish/taghandlers.php(3737) : eval()’d code on line 113” & “Parse error: syntax error, unexpected ‘}’ in /home/public_html/textpattern/publish/taghandlers.php(3737) : eval()’d code on line 1” – and these are above and below the form, so I’m guessing with the first php end tag and the final set of php tags…

I created the file outside of textpattern using <?php … ?> tags and it works OK with no errors.

Am I doing something wrong here, or should I be doing something differently?

Offline

#2 2011-04-19 09:14:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,944
Website GitHub

Re: php on page giving errors

Sadly you can’t escape into and out of <txp:php> tags like you can with <?php...?>. See this not very FAQ for alternatives.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2011-04-19 12:14:21

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: php on page giving errors

Thanks Stef :)

bugger :(

Offline

#4 2011-04-20 00:57:02

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: php on page giving errors

Woohoo – I got this working by doing a simple echo :) The code looks bad, but it works :)

I had one problem though, and I wonder if this is going to cause any security issues.

I was having trouble making this line work in the echo

<form action="$_SERVER['REQUEST_URI']" method="post" enctype="multipart/form-data" class="emailform" >

I just wouldn’t display anything if I used that – so I did some reading on the subject and found this article on the usage of $SERVER Variables in forms which said “If you want the action attribute to point to the current URL, leave it blank. URI references that are blank point to the current resource.”

So I removed it and left it as this, which works:

<form action="" method="post" enctype="multipart/form-data" class="emailform" >

But am I running any security risk here?

Offline

#5 2011-04-20 07:45:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,944
Website GitHub

Re: php on page giving errors

Don’t think it’s any more of a risk than relying on the REQUEST_URI variable. In fact it’s probably safer. The only reason I tend to put something in the action string is so the validator doesn’t complain.

Incidentally if you’re working with $_SERVER vars, you can use TXP’s built-in function serverSet(), e.g. $page = serverSet('REQUEST_URI');


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB