By datacode on
Well, I have been trying to get php code working inside blocks and stories on a test Drupal site with no luck. The php code was initially erroring and now it's just ignored and no error message given. Everything else on my test site works fine within Drupal except this. I have searched for anyone with a similar problem, but found nothing. My initial post on this yielded little help from the community :( I don't know what else to do. Anyone have any suggestions?
Comments
Post example code
Have you tried any of the PHP snippets to see if they work?
http://drupal.org/node/23220
I have several of these working.
Be sure to include all code between
and also check this out for adding more than one PHP snippet to a page:http://drupal.org/node/24258
Good luck.
Yes, I have tried all sorts
Yes, I have tried all sorts of php snippets and also block code examples from http://drupal.org/node/21867. The odd thing is that if test using a very basic php command like...
it will work on my page or block.
But can you give an example
But can you give an example of what doesn't work?
It may be simple.
Be aware that in-node blocks work as if they are in an eval() and so global variables and other things may be out of scope. Nothin to stop most code from working tho.
.dan.
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Return instead of echo
On older Drupal versions, you have to write:
Example?
Hi,
If you posted a simple example of something that you've set up and doesn't work, perhaps we can figure out what's wrong?
I've noticed that sometimes it takes a bit of work to get PHP code to work, I can't tell you how many times I've managed to get a blank page because of some stupid little thing like a missing semi-colon.
Joe
Found your other thread....
Hi,
Found your other thread, the code you mentioned copying there worked for me in a new Page, it's still in my clipboard and I will paste it below. If this doesn't work for you in a new page with PHP blocks activated, then I'd question whether something's wrong with your setup somehow.
This is the code that I know works.
kbaley tried the example
kbaley tried the example code without issues. You may need to post in the original thread more information on specifically what you are doing, any modifications, etc. It's not that we're not interested in helping, just not much to go on. I will give the one generic answer I have, make sure you have no extra white space in your code and the proper open and closing php tags.
-sp
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide
And, for blocks, you need to
And, for blocks, you need to do "return $output", while for pages you'll need to "print $output".
Tags
You have included "< ? php" and "? >" tags around your PHP code right?
Good. Just checking.
------------------------------------------
Drupal Specialists: Consulting, Development & Training
Robert Castelo, CTO
Code Positive
London, United Kingdom
----
Yes I have... I'm working
Yes I have... I'm working with a fresh install of Drupal and only using sample code directly from the Drupal Configuration and customization handbook.
Do you have story type
Do you have story type content?
-sp
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide
PHP version?
What version of PHP are you running? I just ran into problems (not using Drupal) at Earthlink where they had only 4.1.2.
PHP is 4.3.11
PHP is 4.3.11
I still haven't gotten much
I still haven't gotten much help to resolve this. Aren't there any Drupal gurus out there? Please help!
I'm trying, I'm trying....
I'm not sure I'm a guru but I'll try to help, please see my other message above........try that code, let us know if it works or not.
I tried your exact code and
I tried your exact code and still "no go" :(
If I change the input format to "Full HTML" the PHP code does show up (rendered as HTML) in the block - so it is getting into my Drupal database. But when I switch it to "PHP code" it doesn't show up at all.
That's odd....
Ok, are you sure the php filter is on under your administer/input formats configuration?
It's at /admin/filters/2 on my site.
The PHP evaluator needs to be checked for it to work.
I double checked and the PHP
I double checked and the PHP evaluator IS enabled under PHP code.
I may have missed something?
Have you simply set the filter format to allow no filtering of your code. I had to create a new 'filter format' (I think it was called-cannot check-my site is down at present for some other reason).
Anyway the result is that on the edit view you get another choice of formats to submit your page in. I have only allowed that to be visible to admins.
NOTE: this site (drupal.org) does not enable the choices I have mentioned for mere mortal users like me.
Once enabled, all types of script run fine for me (when the site is up that is).
I'll come back later with exact wordings of what I mean when I can acess my site if you still need it.
Are you thining of php type
Are you thining of php type content? That comes with Drupal core depending on your permissions, and no, only 2-3 people have it on Drupal.org itself. You can certainly create additional filters if you need to.
-sp
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide
I am using some JavaScript
I have just commenced working on a new feature of the site which should be very useful to lots of visitors. They will become Species and Genus location maps based on the Google Maps API.
see here for what I am trying to work towards
also my comment
I went ahead and created
I went ahead and created another input format that has no filters enabled. If I apply this formatting to a php code block it is simply rendered as HTML and not executed as php code.
OK, I hope I'm onto something...
OK, I hope I'm onto something... I tried the code in this example (http://drupal.org/node/17142) and it executed correctly from within a "php code" block - so am I safe to assume that PHP is not the issue?
Maybe?
Well, perhaps there's an aspect of PHP that's not activated in the php.ini that's required for this to work?
That's the only thing that comes to mind right now. If you'd like you can post some code that doesn't work in your setup and I'll copy it exactly into mine and see if it works or not.
Could this be a PHP safe mode issue?
Could this be a PHP safe mode issue? (http://drupal.org/node/3386) I believe safe mode is enabled on my server.
Don't know, never run into that one.....
Don't know, it's possible but I have no experience in what kind of problems safe mode causes.
When you bring up the PHP Format configuration, is the PHP evaluator the only filter that's activated for the PHP Input Format? Reason I ask is that from what I'm seeing in my research is that the filters can mess with each other so if there are more than one activated it could cause problems.