How to use Joomla user information in chronoforms

Shows some Tutorials

How to use Joomla user information in chronoforms

Postby Savant on Fri Jun 06, 2008 2:46 pm

How to use Joomla User Information in Chronoforms

Lets pretend you need some user information from a logged in user in your form. But you don't want to have the user type in his user info again and again, because he already did it while registering for the Account.

So you are looking for a possibility to automatically fill in the users name, username, e-mail adress into the chronoform, so the user doesn't have to type it again.

Here's the (easy!) solution with a little bit help of the Joomla Framework:

Enter (or copy & paste) the following code at the beginning of your chronoform HTML-Code:

Code: Select all
<?php
// Get user-information from Joomla
$user = &JFactory::getUser();
?>


In the form itself use the following syntax to fill either inputboxes or hidden fields with the wanted user information like that:

Fill the user info into an inputbox:
Code: Select all
<input type="text" name="username" id="username" size="20"
maxlength="40" value="<?= $user->name; ?>" />


The "value"-tag and the following snippet of php will insert the username ($user->name) into the text field so the user is abled to leave it as it is or change it if needed. Convenient.

Fill the user info into a hidden field:

Code: Select all
<input type="hidden" name="username" id="username"
value="<?= $user->name; ?>" />


This will add a hidden field to your form which will transfer the username to the recipient without printing it on the screen. Usefull if you want to transfer lot of info in the form, which the user doesn't need to see, but the recipient does.

If you want to user other info than the user name you just replace the php snippet part with:

Code: Select all
<?= $user->username; ?>
<?= $user->email; ?>
<?= $user->password_clear; ?>
<?= $user->id; ?>
...


For the username, the users e-mail address and so on...

A full list of the possible user info you can use with this function is available here:

http://api.joomla.org/Joomla-Framework/User/JUser.html

Just a small feature, but comes in handy from time to time. :-)

Haphe phun, Savant
Savant
Fresh Boarder
 
Posts: 11
Joined: Mon Apr 28, 2008 2:59 pm

Re:How to use Joomla user information in chronoforms

Postby GreyHead on Fri Jun 06, 2008 2:58 pm

Hi Savant,

Thanks - good info!

Bob

PS Line breaks seem to have gone to pot at the moment so anyone using this code cut and paste with care!!!
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3461
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:How to use Joomla user information in chronofor

Postby Astrid on Sun Jun 08, 2008 9:21 pm

Great! Is there a way to include user info from custom fields made with Community Builder?
Astrid
Fresh Boarder
 
Posts: 15
Joined: Tue Apr 15, 2008 10:04 am

Re:How to use Joomla user information in chronofor

Postby GreyHead on Mon Jun 09, 2008 1:54 pm

Hi Astrid,

Yes, I think that the Profile PlugIn is the simplest way of doing this. There have been a couple of recent conversations about it here.

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3461
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany


Return to ChronoForms How To

Who is online

Users browsing this forum: swlabhot, Yahoo [Bot] and 1 guest