Forums

GetUser functions implemented within Wizard

breid 12 Apr, 2011
I'm using V4.

I'm trying to get the current Joomla session user included in the email sent from the form. I've seen several references on these forums to using the JFactory GetUser statement to get this and include as a hidden form field value, but every code example has to do with editing the form code directly.

This form will be maintained by users who aren't HTML/PHP savvy, so I need to include this functionality in the form Wizard so it won't be overwritten.

I have tried using the PHP statements in the Email template, but received parse errors.

I have tried putting the JFactory statement in a custom code block on the load action, then using php echo for the form field default value, but I get parse errors again.

Is there any way I can accomplish this WITHOUT inserting code into the form's raw code window? Something that will not be overwritten when the form is edited with the Wizard Edit?
breid 12 Apr, 2011
I solved my own problem - I had errors in my php code.

I was able to output successfully in the e-mail template with

<?php $my = JFactory::getuser(); echo $my->name; ?>
GreyHead 13 Apr, 2011
Hi breid,

That looks fine - I think you could also use a Custom code action to add the user info to the form data:
<?php
$user =& JFactory::getUser();

$user_array = array(
  'username',
  'name',
  'email', 
  'id'
);
if ( !$user->gid ) {
  $user->username = 'Guest';
  $user->name = 'Guest';
  $user->email = '';
} 
foreach ( $user_array as $v ) {
  $form->data[$v] = $user->$v;
}
?>
Then you can use {username}. {name}, etc in the template.

Bob

Bob
algous 31 May, 2011
Hello, thanks for this powerful component.

If you have php error, juste replace
$user>username = 'Guest';

by
$user->username = 'Guest';


Bye😉
This topic is locked and no more replies can be posted.