Jump to content


Photo

php appears in the source code


  • Please log in to reply
8 replies to this topic

#1 surrealillusions

surrealillusions

    Etomite Forum Newbie

  • Member
  • 4 posts

Posted 06 July 2009 - 05:52 PM

Hi all,

I have made a custom script for a site that uses etomite. And part of that I need some php above the doctype in the main template. I have enabled the "Allow Embedded PHP" setting for me to do this. However, the php code, even though it works, it appears in the source code.

Only it doesnt appear on the index.php?id=20 page.

This maybe a misunderstanding of PHP on my part as I've not come across this problem before, and this snippet of PHP i took off the internet as I wasnt sure on how to grab the page name.

But I've posted it here now as it appeared when i switched the allow emebbed php setting on.

Heres the php code that appears:

<?php
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER["QUERY_STRING"]))
	$url .= "?".$_SERVER['QUERY_STRING'];
if ($url== "http://www.example.co.uk/index.php?id=20") {
include('somefile.php');
}
else {
}
?>

Any suggestions would be appreciated.

:)


#2 Dean

Dean

    Loves Etomite Forums!

  • Admin
  • 4,786 posts

Posted 07 July 2009 - 08:52 AM

Tell us what you're trying to do, so we can tell you if there's another way to do what you're trying to achieve without having to use raw php :)

#3 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 07 July 2009 - 01:27 PM

Ditto what Dean said... The problem could be due to the fact that you are putting PHP code ABOVE the DOCTYPE statement which is causing an illegal whitespace issue... We really do need to know what it is that you want to include because there may be an easier way to perform the task, like using a Snippet to either hold the code or to perform the include...

#4 surrealillusions

surrealillusions

    Etomite Forum Newbie

  • Member
  • 4 posts

Posted 07 July 2009 - 02:29 PM

Hi,

Thanks.

I'm trying to make a custom contact form script for the site. But i only want to include the process on the contact page, as to not to parse irrevelant php code on every page. I'm relatively new to etomite so there is probably a better way of doing this.

I've tried adding the PHP as a snippet and adding the [[somesnipper]] bit at the top, but i get

Parse error: syntax error, unexpected '<' in /path/to/site/public_html/index.php(508) : eval()'d code on line 1

#5 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 07 July 2009 - 02:33 PM

I'm trying to make a custom contact form script for the site. But i only want to include the process on the contact page, as to not to parse irrevelant php code on every page. I'm relatively new to etomite so there is probably a better way of doing this.

I've tried adding the PHP as a snippet and adding the [[somesnipper]] bit at the top, but i get

Parse error: syntax error, unexpected '<' in /path/to/site/public_html/index.php(508) : eval()'d code on line 1



When using Snippets, you do not use opening <?php or closing ?> PHP tags as they are implicitly added by the parser... Including the tags confuses the parser which is why you are getting that error... They can be remarked out if you don't want to remove them completely...

#6 surrealillusions

surrealillusions

    Etomite Forum Newbie

  • Member
  • 4 posts

Posted 07 July 2009 - 07:07 PM

Ah..gotcha.

Still chasing errors though.

Is there a simpler way of doing this?

Basically I have this:

--code to deal with form if submitted--
--html page stuff, with form where theres a hidden field to tell the php stuff above its been submitted, as well as error messages built into the form--
--ending of html--
--closing bracket of form code at the top, as, when the form is not submitted, it displays the page, rather than sending an email--

This works on my own sites and template systems, but I cant get it to work on the Etomite cms system. When everything is in place as it should be, it says

Parse error: syntax error, unexpected $end, in the included file.

But there shouldnt be an unexpected end, as the closing bracket is at the end of the page, as the php code encloses the rest of the page.

Without pasting the entire PHP script, dont think theres much else I can do apart from vent my fustration with it here in this post..which isnt going to help anyone.

#7 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 07 July 2009 - 09:26 PM

There are several limitations, if you consider them limitations, when working with Snippets, as discussed in the Documentation section of this site... The biggies are the PHP tags and no direct output via print() or echo()... The parser buffers all output until all parsing is complete and then it renders the page...

I sure everything you want to do can be done within Etomite because I code within Etomite exclusively and have written more than a few form handling snippets as well as complete custom data management interfaces... Most of what I code is Etomite based internal MVC modules which make use of Snippets for the Controllers and Models and Chunks for Views...

Feel free to PM me some of the code you are working with and I'll try to give you some pointers that may make your transition easier... Or, if you have a site you're working on, and would like, provide me with login spec's for the site...

#8 Dean

Dean

    Loves Etomite Forums!

  • Admin
  • 4,786 posts

Posted 07 July 2009 - 10:19 PM

Ralph - you have a ticket in the support desk :)

#9 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 09 July 2009 - 05:50 PM

Here is a copy of what I posted in the ticket system because this is not an Etomite bug...

I just took a quick look and it appears that the problem stems from you placing Chunk code in a Snippet... Snippets should only contain valid PHP code... Chunks on the other hand, when embedded PHP is enabled, can use a mix of HTML, Javascript, and PHP blocks which do need PHP tags... Also, in order to use the Etomite class object with a Chunk, or what I call an Active Chunk, you must also enter the line <?php global $etomite; ?> before attempting to access any parts of the $etomite object...

Active Chunk Example:

<?php global $etomite; ?>
   
   <div id="activeChunk">
   Data: <?php date($etomite->config['date_format'], time()); ?><br/>
   Time: <?php date($etomite->config['time_format'], time()); ?><br/>
   URL: <?php echo $etomite->makeUrl($etomite->documentIdentifier); ?><br/>
   </div>

The above code should populate both the date and time based on the format settings stored in the configuration panel... It will also render the URL of the current page...

Hope this helps, but this is something that should be discussed with the forums as opposed to here because this is not related to Etomite Bugs but, rather, Etomite usage related...

See http://dahlgren.slyip.com/ and http://ralphdahlgren.com/ for Etomite coding examples...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users