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:
Quote
 
 
# 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
Quote
 
 
# 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.
Quote
 
 
# 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.
Quote
 
 
# 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
Quote
 
 
# Wooshtek 2012-02-07 00:35
Can a it do PHP forms like e.g. registration form? If yes, can provide a sample code.
Quote
 
 
# 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
Quote
 
 
# sunanda 2012-02-22 22:16
after entering code into article where should we check the output of php file
Quote
 
 
# 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
Quote
 
 
# 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.
Quote
 
 
# 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
Quote
 
 
# double-dee 2012-02-27 19:14
No error message. The php code is displayed.
Is multi-lines a settings?
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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?
Quote
 
 
# 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?
Quote
 
 
# 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
Quote
 
 
# 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:
Quote
 
 
# 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.
Quote
 
 
# 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
Quote
 
 
# Anithagutta 2012-07-04 23:04
dircetPHP is not working with joomla2.5.4
it's not showing form in articles
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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 '
Quote
 
 
# 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?
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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.
Quote
 
 
# 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.
Quote
 
 
# 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! ^_^
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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!
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# sohal 2013-01-15 09:05
another issue found....
it didnt work for me when i used capital letters in (
Quote
 
 
# 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 .....
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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
Quote
 
 
# 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?
Quote
 
 
# kksou 2013-01-31 05:10
Hi,

Can you please try:

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

and see if it works?

Regards,
/kksou
Quote
 
 
# 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.
Quote
 
 
# kksou 2013-01-31 05:09
Hi,

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

Regards,
/kksou
Quote
 
 
# 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:
Quote
 
 
# Harris Marfel 2013-03-03 02:40
This plugin only work if you use basic PHP code. not the advance php code.
Quote
 
 
# 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
Quote
 
 
# sawan gupta 2013-03-04 02:43
hi frnd
how i can override k2 components which convert to the list from to menu tab.
Quote
 
 
# 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
Quote
 
 
# sawan gupta 2013-03-04 02:45
hi frnd
how can i edit normal html or php form to joomla 2.5
Quote
 
 
# AlexMitvix 2013-04-07 14:56
Great plugin!!! I love it!
Quote
 
 
# 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.
Quote
 
 
# 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:
Quote
 
 
# 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
Quote
 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Links - Classes - Social Business - BPM - Web - General
Copyright © 2006-2013. kksou.com. All Rights Reserved