Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
Re: php on page giving errors
Thanks Stef :)
bugger :(
Offline
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
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
Pages: 1