How to enter HTML tags, javascript and PHP codes in Joomla 2.5?
Written by kksou   
Thursday, 26 January 2012
The following works for Joomla 3.0 and above too.

If you are using DirectPHP, you can use the following to enter PHP codes in your article:

  1. Login as administrator.
  2. Goto Global Configuration.
  3. Click the tab "Text Filters" (first one from the right).
  4. For all Filter Groups, the default is "Black List". For the respective Filter Groups, change the Filter Type from "Black List" to "No Filtering".
  5.  

  6. For example, if you are only administrator, change the Filter Type of the Super Users to "No Filtering". Leave all other remain as "Black List".
  7.  

  8. Don't forget to click "Save & Close"
  9.  

That's it! You should now be able to enter PHP codes in your Joomla article.

Note: The above applies to Joomla 2.5 and above only.


 

Comments  

 
+2 # Phoebez 2012-01-27 21:59
And don't forget to enable the plug in so you don't feel foolish for half an hour like I did. :oops:
 
 
# azerty989 2012-02-02 16:53
Hey,

It does work for me, I have joomla 2.5.1, and did set up as above.
- plug in is published;
- text filters in global config sets up to "no filter";

after typing into the article:

the editor uses html comments like :

Is direct php working for 2.5.1 ? or I forgot to do something else?
Thank you
 
 
# azerty989 2012-02-02 16:54
Sorry all,

I forgot "NOT" in my previous comment.
It does NOT work for me with joomla 2.5.1.

Looking forward to hearing from you guys.
 
 
# azerty989 2012-02-02 17:05
Never mind it seems to work now.
I figured out that you cannot type your code into the html source editor.
copy and paste the php code straight into the editor and it works.
 
 
# kksou 2012-02-02 17:11
Hi,

Yes, you should enter the code in the WYSIWYG editor. DO NOT click the "HTML" button and enter the code in the html source editor.

Regards,
/kksou
 
 
# Wooshtek 2012-02-07 00:35
Can a it do PHP forms like e.g. registration form? If yes, can provide a sample code.
 
 
# kksou 2012-02-07 01:26
Hi,

Please refer to: How to display and process forms in a Joomla article using DirectPHP?

http://www.kksou.com/php-gtk2/Joomla/How-to-display-and-process-forms-in-a-Joomla-article-using-DirectPHP.php

Regards,
/kksou
 
 
# sunanda 2012-02-22 22:16
after entering code into article where should we check the output of php file
 
 
# kksou 2012-02-22 22:22
Hi,

I suppose you are referring to using DirectPHP.

This is a plugin. As name suggests, it's for use within a Joomla article.

So try entering
echo "test123";
in an article.

You should be able to see "test123" somewhere in your article.

Once you see that it works, you can slowly add more complicated PHP commands within your article.

Regards,
/kksou
 
 
# double-dee 2012-02-27 19:01
I have to enter in the php open tag on every line. Is this the intended design or am have not configured the plugin fully.
 
 
# kksou 2012-02-27 19:04
Hi,

Have you tried using multi-lines? It should work.

If not, what's the error messages that you see on the screen?

Regards,
/kksou
 
 
# double-dee 2012-02-27 19:14
No error message. The php code is displayed.
Is multi-lines a settings?
 
 
# kksou 2012-02-27 23:48
Hi,

Are you saying that if you enter:
echo 'test123';

It works ok.

But if you enter:
echo 'this is line1';
echo 'this is line2';

Can you show me the URL displaying the 2 lines above, i.e.
echo 'this is line1';
echo 'this is line2';

It doesn't work?

Also, what are the PHP commands that you are trying to run?

Regards,
/kksou
 
 
# Shaun 2012-04-19 06:40
Hi,

Nice little tool but the \ of "\n" for newline is being stripped out of my code. I've turned filtering off. Anything else I can do?

Thanks, Shaun
 
 
# kksou 2012-04-23 07:11
Hi,

If you take a look at the source code, there's no lines that strip the \n. So guess it's by the Joomla editor.

You might want to try some other Joomla editor that allows direct editing in raw HTML.

By the way, why would you need the \n? They are "transparent" in an HTML page, isn't it?

Regards,
/kksou
 
 
# Mortenjs 2012-05-02 05:57
Hi I have tried to paste in this line.

Portfirmaet.dk Anmeldelser

Should it work with this module/plugin?
 
 
# Obaeissa 2012-06-13 17:12
Hi I'm using Joomla 2.5, I'm using customise form result will be send to another php file to processed with DB connection and do the query is it possible to use DirectPHP in an article to connect to DB and do the query?
 
 
# kksou 2012-06-15 08:07
Hi,

If you know PHP well and know what you're doing, you should be able to do it.

There's no magic in DirectPHP. The plugin simply grabs all the PHP statements that you've written within the PHP tag and pumped them through the standard PHP eval() function.

Just remember that you are running DirectPHP within the Joomla article and Joomla framework. What this means is that if you connect the DB to another mysql database, you MUST make sure that you connect the DB back to the joomla database at the end of the DirectPHP statement.

Otherwise, you will find that your entire Joomla DB connection is gone and your Joomla page will not render properly.

Regards,
/kksou
 
 
# Jens 2012-06-30 02:14
It don't seem to work in Joomla 2.5.6. The plugin is installed and enabled, and Super Users has no fliter.
I'm pasting my code in a standart article with the standart editor, and the output is just the code as text. :sad:
 
 
# Jens 2012-06-30 04:09
Quoting Jens:
It don't seem to work in Joomla 2.5.6. The plugin is installed and enabled, and Super Users has no fliter.
I'm pasting my code in a standart article with the standart editor, and the output is just the code as text. :sad:


The problem is solved. Apparently the start and end tags is supposed to be on the same line as the commands.
 
 
# kksou 2012-07-08 19:31
Hi Jens,

It does not need to be all on the same line.

1) Please use the WYSIWYG mode (not the HTML mode).

2) Instead of , use shift-. will generate . shift- will generate

Internally, DirectPHP will convert all and to \n.

Please try the multiple lines one more time and let me know if it works.

Regards,
/kksou
 
 
# Anithagutta 2012-07-04 23:04
dircetPHP is not working with joomla2.5.4
it's not showing form in articles
 
 
# kksou 2012-07-08 19:36
Hi,

1) Please try a simple PHP statement first e.g. echo "test 123";

Does it work?

2) If (1) works, then the problem is with your PHP statements producing the form.

What's the error messages that you see on the screen? (You might need to turn on error_display in php.ini.)

By the way, DirectPHP uses the standard PHP eval() function. If you have played with this function before, you will know that the error messages returned by eval() is not useful at all. It's almost impossible to debug based on the error messages returned by eval().

As such, if you really want to debug errors in your PHP statements, you might want to copy and paste your entire PHP scripts into a standalone .PHP file, and use DirectPHP to do a require_once() or include() to include that .PHP file. In this way, you will find that the error messages (if there's any) will be a lot more meaningful.

Once your scripts runs ok in the standalone file, you can then copy and paste the entire script back into DirectPHP.

Regards,
/kksou
 
 
# kksou 2012-07-08 19:41
Hi,

You might also want to take a look at this article: How to display and process forms in a Joomla article using DirectPHP?
Link here: http://www.kksou.com/php-gtk2/Joomla/How-to-display-and-process-forms-in-a-Joomla-article-using-DirectPHP.php

Regards,
/kksou
 
 
# michael_e 2012-08-08 12:35
I am trying to embed the phpfreechat chat engine in the page but i get this error:

Parse error: syntax error, unexpected '
 
 
# Smuj 2012-08-11 14:48
Great plug-in! I'm using Joomla 2.5 and I'm unable to use FROM in quotations while inside a php bracket. I've currently solved this by using FR"."OM but it's going to get messy if I'm going to continue to write sql commands like that. Any ideas?
 
 
# kksou 2012-08-17 01:40
Hi,

That's strange. If you take a look at the source code, it doesn't detect the string "FROM".

It might be due to your other plugins.

Alternatively, you can do something like
$a = 'FROM";

Then every time you need to use "FROM", you can use $a.

Regards,
/kksou
 
 
# millsy 2012-09-03 03:19
Hi,
I've just installed this in 2.5. activated and 'no filtered' the superuser but code only seems to work when logged into the frontend as superuser.It just displays the code when not logged it. put 'no filter' on public (temporarily) and it still just displays the code and doesn't run.
I'm using JCE editor if there's some setting within this addon i need to alter
Have i missed something
 
 
# tibbus 2012-09-10 13:36
Hi, with my php code i connect to another DB and how you said my page it show now SERVER ERROR, how i connect back to joomla DB to work properly ?


Quoting kksou:
Hi,

If you know PHP well and know what you're doing, you should be able to do it.

There's no magic in DirectPHP. The plugin simply grabs all the PHP statements that you've written within the PHP tag and pumped them through the standard PHP eval() function.

Just remember that you are running DirectPHP within the Joomla article and Joomla framework. What this means is that if you connect the DB to another mysql database, you MUST make sure that you connect the DB back to the joomla database at the end of the DirectPHP statement.

Otherwise, you will find that your entire Joomla DB connection is gone and your Joomla page will not render properly.

Regards,
/kksou
 
 
# tibbus 2012-09-13 17:43
nvm, now it works ok, so seems like it's no problem to connect to another database from joomla via php, i used sourcerer not directphp but anyway.
 
 
# auto title loans 2012-10-28 20:38
I just read your article on How to enter HTML tags, javascript and PHP codes in Joomla 2.5? | Joomla Tips & Techniques and want to thank you for it.
 
 
# Smuj 2012-10-28 21:02
Quoting kksou:
Hi,

That's strange. If you take a look at the source code, it doesn't detect the string "FROM".
...
Regards,
/kksou


Turns out it's a theme problem. I think they theme is trying to stop SQL injections and it's messing with your plug-in.
You're plug-in is quite perfect for many of my uses. I use custom PHP and SQL through modules instead of components every time I have an idea. Probably should still learn.
Awesome plug-in still! ^_^
 
 
# azza 2012-11-21 03:32
this plugin does it work with joomla 2.5.8 ? i've installed but the code appears idem in frontend
 
 
# kksou 2012-11-26 00:51
Yes, it works. Did you enable the plugin?

Please don't try with long codes first. Try something simple like
echo "test123";
and see if it works first.

Regards,
/kksou
 
 
# Basil Clarke 2012-11-27 14:48
Tried it out for the first time today. I could only get it to work by writing the php on a single line - and because I had code that queries a database and then writes out the contents of particular fields, I had to put the code in a separate php file, then insert an include in a Joomla module. But the end result is that it does work!
 
 
# kksou 2012-11-28 01:14
Hi Basil,

Since the one-line version works, this is what you can try.

1) When you enter multiple lines, if you are using the default Joomla editor, try to use shift-enter instead of enter between lines. Enter will generate [p] and [/p]. Shift-enter will generate [br]

2) Try 2 lines first:
echo 'this is line 1';
echo 'this is line 2';

3) If (2) works, you can slowly add more lines and replace with your codes. Do it bit by bit, so that it's easier to debug if there's anything wrong.

Of course, if you're ok with the one-line version to include your other .php files, that's fine too!

Regards,
/kksou
 
 
# syed rizvi 2012-12-19 17:46
Hi,

I have 2 questions. First of all, I have downloaded the DirectPhP for Joomla 2.5 and set it up mentioned in this article. I'm new to Joomla. I don't know where should I put DirectPhp.php file to see the effects. In other words, I want complete instructions on printing "hello world" on my website using DirectPhp.

Secondly, I have a new website built on Asp.net which requires Single sign on from my Joomla 2.5 website. So, when a person has logged into my Joomla website, a menu item should appear which will direct him to my asp.net website along with passing username in encrypted form. I'm really struggling with how to do this and need solution for this ASAP. Please, I would highly appreciate your suggestions. Thanks
 
 
# kksou 2012-12-19 22:34
Hi,

1) For your first question, DirectPHP is a plugin. As the name suggests, a plugin is for use within a Joomla article. So to use DirectPHP, you go to the Article Manager, create a new article, and plugin in your PHP codes within the article.

2) I'm not familar with .net. So it's difficult for me to help you here. Would suggest you post your question in the official joomla.org forum. Someone might be able to help you there.

By the way, if you're thinking of using DirectPHP to resolve your second question, then this might not be the right tool. As mentioned in (1), DirectPHP is for use within a Joomla article. For your situation, you should be looking at creating your own module or plugin.

Regards,
/kksou
 
 
# syed rizvi 2012-12-20 10:07
Hi kksou,

Thanks for your reply. I appreciate it. You don't have to know anything about .Net. Just that I have a session variable "username" in joomla 2.5 that I need to pass as parameter to www.hapw.com/PLW/Default.aspx?username=value. I want this to be done with a menu item in joomla 2.5 that will contain hyperlink to the .Net website. The thing I don't understand is that even if I create a new menu item, where should I insert the underlying php code to get my session variable value and add append to the above query string. Thanks.

Regards,
Syed
 
 
# KarenL 2013-01-03 17:39
Hi kksou,

Not sure whether it's the plugin or some php set up issue.
I'm on Joomla 2.5.8.
Plugin is enabled, no filtering for superuser.
All I want to do is to put a copyright date using php date function but it doesn't work.

When I try in WYSISYG
echo "test123";

What appears on the screen is
echo "test123";

Any ideas what could be wrong?

Thanks,
Karen
 
 
# kksou 2013-01-03 17:45
Hi Karen,

Did you put the php tag:

[?php echo "test123;" ?]

note: please replace square bracket above with angle brackets.

Regards,
/kksou
 
 
# sohal 2013-01-15 09:05
another issue found....
it didnt work for me when i used capital letters in (
 
 
# hadsub 2013-01-23 07:43
'm have developed a web site using joomla1.5 and it has MYSQL DB php code of my own. it works well in joomla1.5. but the same code of php, the form that i have used in joomla1.5 is not working in joomla2.5? any one have any idea about this Help .....
 
 
# kksou 2013-01-25 19:34
Hi,

You need to give people more clues in order to know where might be the problem e.g.

1) What's not working?

2) Are there error messages that you see? If yes, what are the error messages?

3) Any other things that you see on the screen? (e.g. your PHP codes)

4) Are the code still there when you edit the article?

Regards,
/kksou
 
 
# KarenL 2013-01-26 12:30
Quoting kksou:
Hi Karen,

Did you put the php tag:

[?php echo "test123;" ?]

note: please replace square bracket above with angle brackets.

Regards,
/kksou


I had missed out the < > but when I put replaced the square brackets with angle brackets I received the following error:

Parse error: syntax error, unexpected $end, expecting ',' or ';' in /home/XXXXXX/public_html/plugins/content/DirectPHP/DirectPHP.php(58) : eval()'d code on line 1

Any other suggestions?

Cheers,
Karen
 
 
# kksou 2013-01-26 17:25
Hi Karen,

Sorry, my typo.

It should be:
[?php echo "test123"; ?]
note: please replace square bracket above with angle brackets.

Please give it a try one more time and let me know if it works.

Regards,
/kksou
 
 
# Rob Genspoon 2013-01-30 10:31
If I use something like

[?php echo "blah"; ?]

all is well.

If I get "fancy" like

[?php
$x="blah";
echo $x;
?]

Nothing happens.

Please advise?
 
 
# kksou 2013-01-31 05:10
Hi,

Can you please try:

[?php $x="blah"; echo $x;?]

and see if it works?

Regards,
/kksou
 
 
# Jaderson 2013-01-31 03:36
Olá, eu estou precisando colocar código PHP em uma widgetkit mas alguns códigos desaparecem e os que ficam não aparecem o resultado. somente o código.
 
 
# kksou 2013-01-31 05:09
Hi,

Sorry. Have only learned English. Would you mind to write your question in English?

Regards,
/kksou
 
 
# ganesh2k 2013-02-01 02:53
plz help i am running a joonla Virtue-Mart
site a local store in India i need to change Rs symbol to rupee symbol they i have java-script http://cdn.webrupee.com/js which convert all Rs or RS to that symbol plz help me how to add the script to site r any other method. my site is www.nalam.in(under development)mai l me so i can send username-password for site plzzz reply back... :sigh: :sigh:
 
 
# Harris Marfel 2013-03-03 02:40
This plugin only work if you use basic PHP code. not the advance php code.
 
 
# kksou 2013-03-07 07:08
Hi,

If you look at the source code, this plugin simply grabs all your PHP codes and pump them into the standard PHP eval() function.

The PHP eval() function is not that smart to differentiate between simple or advanced plugin. Any valid PHP code that can be processed by eval() can also be processed by DirectPHP.

Regards,
/kksou
 
 
# sawan gupta 2013-03-04 02:43
hi frnd
how i can override k2 components which convert to the list from to menu tab.
 
 
# kksou 2013-03-07 07:09
Hi,

You cannot do this with DirectPHP. DirectPHP is a content plugin. It's supposed to be used within a Joomla article.

You need to change the source code of the k2 components.

Regards,
/kksou
 
 
# sawan gupta 2013-03-04 02:45
hi frnd
how can i edit normal html or php form to joomla 2.5
 
 
# AlexMitvix 2013-04-07 14:56
Great plugin!!! I love it!
 
 
# Se 2013-04-12 03:04
Very neat plugin. A lot of the problems mentioned in this board can be solved by simply going to Joomla "Global configuration", change the default Joomla editor to "Code Mirror" and everything works a treat. Thanks.
 
 
# Zadra Design 2013-05-01 17:01
I have used this plugin for years and love it; however, I cannot get it to work in Joomla! 3.1. Any idea on when it will be updated? I have set it to no filtering and tried both with and without the text editor, but on the front end the triangle brackets are replaced with HTML comments, for example:
 
 
# kksou 2013-05-01 21:25
Hi,

I'm using DirectPHP on my Joomla3 site without any problem.

Have you tried other editors and see if it works?

If possible, try setup a fresh install of Joomla3 somewhere on your site and then DirectPHP. This will allow you to see if it works on your machine at all, or if it's conflicts with your other plugins.

Regards,
/kksou
 
 
# peterson10011 2013-06-17 23:19
This is a very useful information. Thanks for sharing.
PHP training in Chennai
 
 
# alex0098 2013-07-05 09:21
verry nice share i like it
cam a cam.
cam a cam.
 
 
# bogi 2013-07-11 08:42
how can I use the user's session?
for example, I want to create a php script that if it is user A that access the script it will echo "apple", and if it is user B it will echo "orange"

thanks in advance
bogi.imtelkom.ac.id
 
 
# kksou 2013-07-11 23:59
Hi,

DirectPHP is not used for such a purpose.

For your case, you might need to develop your own plugins and incorporate those PHP codes right inside your plugin, instead of through another layer of content plugins such as DirectPHP or any others.

For user sessions, you can google for "PHP sessions tutorial" and there will be many resources and sample codes for your use.

Regards,
/kksou
 
 
# Bob Scott 2013-07-19 17:28
I am also having problems with the multiline php code:
Today's date (according to this web server) is



It produces the following parsing error:
Parse error: syntax error, unexpected '
 
 
# Bob Scott 2013-07-19 17:46
Sorry, previoius comment meaningless - it stripped my code so I'll try again. I'm having trouble with multiline line like others - Shift-Enter didn't solve it using TinyMCE. I get a Parsing error.
Single line works OK with TinyMCE and multiline works if I use CodeMirror editor. Joomla 2.5.11, MySQL 5.0
[?php
echo date('l, F jS Y.');
?]
Any advice (any more info needed)?
 
 
# kksou 2013-07-20 17:27
Hi Bob,

That's strange. It should work.

I couldn't know the problem without further info.

Are you ok with mysql? If yes, can you go to the backend mysql of your joomla, and locate the record of this article in the table jos_content.

Please email me the entire content of the 2 fields: introtext and fulltext - this should give me enough clue to know where the problem is.

Regards,
/kksou
 
 
# fredas 2013-07-22 15:15
It's not working with Joomla 3.1.1.

I installed the plugin and set settings: to "no filter", plugin is activated and i put simple code in to wysiswyg (tinymce) and get the hole code as a plain text:
Now is:

and I get this code displayed on the frontpage. :-|
 
 
# kksou 2013-07-24 01:37
Hi,

If you see the entire code displayed, it means the code has not been processed at all (i.e. DirectPHP is not running).

If your plugin is enabled, it could mean that it's conflicts with some other plugins.

To only way to ascertain this is to install a fresh install of Joomla somewhere on your site and then install just the DirectPHP plugin. This will allow you to see if DirectPHP run on your server at all.

Regards,
/kksou
 
 
# lisaedward 2013-09-19 01:53
This is really nice. Thanks for sharing this article
PHP training in Chennai
 
 
# Ole M 2013-09-23 02:03
Hi,

I will use directPHP on my joomla 3.1.5 installation. If I use the following php () in an article - it works. But if I take it in an own module it doesn´t work. I use directPHP in my joomla 2.5.x in an own module too and there it works. Any help? thx
 
 
# jrrabi 2013-10-26 14:48
Quoting Phoebez:
And don't forget to enable the plug in so you don't feel foolish for half an hour like I did. :oops:

:-* hehe, so often to me 8)
 
 
# John Fidge 2013-11-10 13:56
Hi,
What have I done wrong?
I am using Joomla 3.1.5.
I downloaded your zip file, used Extension Manager to install it,enabled DirectPHP in the Plugin Manager and checked that the Super User Filter Type was set to No Filtering.
I then opened one of my articles and hit the Toggle Editor button and added a separate line with on it. On saving the article, TinyMCE had put comment braces around my PHP code.
 
 
# kksou 2013-11-10 14:47
Hi John,

Try to enter the code from the backend Article Manager and see if it works.

Also, when you enter the PHP code in the Article Manager, please use the default WYSIWYG mode (as oppose to the HTML mode).

Please enter something simple first for testing e.g. echo 'test123';

If it works, then you can start entering more lines. It's difficult to debug in this mode (the PHP codes are run using PHP's standard eval() function). So try entering a couple of lines at a time.

Regards,
/kksou
 
 
# John Fidge 2013-11-10 15:04
Hi,
Found it. You don't go into the Editor, but do it on the WYSIWYG page.
No need to reply now, thanks.
I found the answer in one of your other posts above.
 
 
# Rhys Crawford 2013-12-12 12:16
I cannot get this to work in Joomla 3.2. I am using the codemirror editor, and I have checked that the code is being inserted into the database correclty. However on displaying the page Joomla (or a template) is commenting out my PHP. Although it might be the template, I have tried multiple templates, so I think it's the Joomla core. Any ideas?
 
 
# Rdel 2014-01-01 06:09
Inside the TinyMCE, I'm trying to display "More Info" text that links to the article's title. Is it possible using this plugin or is it something beyond the scope of this plugin?

I'm using Joomla 3.x.

Thanks
 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved