Run PHP code in Field Element

Parisi

Member
I have a field element that I want to display the currently logged in Joomla user's name.

I have the following in the Default

$user = JFactory::getUser();
$name = $user->get('name');
return $name;

But it fails - I cannot even save the element. I get
Error 403 - Forbidden
You don't have permission to access the requested resource. Please contact the web site owner for further assistance.

I know this is something silly.

Please help.
 
Are you running any 3rd party security plugins in J!?

Is there anything in your httpd server logs about mod_security triggering when you try and save the page? If you don't have access to your server logs, you may need to ask you host support to see if mod_security (or similar, like Suhosin) is triggering on that PHP code in the default.

Basically, a 403 when submitting a form which has PHP or MySQL fragments in the form being submitted is almost always due to a security plugin triggering, thinking that it is a hack.

-- hugh
 
I just looked at modsec (WHM) and it is using OWASP ModSecurity Core Rule Set V3.0. I tried to turn it off and the same 403 error. I also, set logging to "Log all transactions" but that does not seem to create any logs that I can find.

Next I changed the settings to Not process any rules and now it allows it to be saved even if I turn those back on.

But, when I run the front end the field does not have a name in it...
 
Try putting in a var_dump ...

Code:
$user = JFactory::getUser();
$name = $user->get('name');
var_dump($name); exit;
return $name;

... then load a new form, and see if you get a white page with just the debug output of the name on it.

Just to be sure - you know that defaults only get run on a new form, right? Not when editing an existing form.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top