• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Pre-fill Name & email address if user is logged in

Pre-fill Name & email address if user is logged in 16 years 3 months ago #1648

  • kuhsay
  • kuhsay's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Put the following code in \"Script called on form display\". If the user is logged in, it will automatically grab their name and email address they are registered with and load them in the forms. You can also use username if you want. If the user is not logged in the fields are simply left blank.
global $my;
 
if($my->id){
    foreach($fields as $i=>$field){
        if($field->name=='fullname') $fields[$i]->default_value = $my->name; //Assuming your rsform text field is called \"fullname\"
        if($field->name=='email') $fields[$i]->default_value = $my->email; //Assuming your rsform email text field is called \"email\"
    }
}

Special thanks to Alex for getting this to work. B)
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 16 years 2 months ago #2046

  • dniezby
  • dniezby's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 136
  • Thank you received: 2
If the user is logged in all you have to do is set the default value to
{jos_username}
{jos_name}
{jos_email}
Dave Niezby
www.nsfilms.com
Nightshade Studios, CEO
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 16 years 1 month ago #2112

  • alex
  • alex's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 443
  • Thank you received: 3
If you're using Joomla 1.5 then the code should look like:
$my = & JFactory::getUser();
if($my->id){
    foreach($fields as $i=>$field){
        if($field->name=='fullname') $fields[$i]->default_value = $my->name; //Assuming your rsform text field is called \"fullname\"
        if($field->name=='email') $fields[$i]->default_value = $my->email; //Assuming your rsform email text field is called \"email\"
    }
}
Alex.
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged 15 years 10 months ago #3208

I tried that dniezby and it doesn't work.
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged 15 years 10 months ago #3236

where is this script located - on form display?

Thanks

Rick<br><br>Post edited by: richard.w.mann, at: 2008/06/07 22:15
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is logged 15 years 10 months ago #3237

OK,

I found where to enter the code but now when I go to the form page on my site I get the following error:

Warning: Invalid argument supplied for foreach() in /home/#####/public_html/components/com_rsform/controller/functions.php(777) : eval()'d code on line 3

What could be causing this?

Thanks

Rick
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is logged 15 years 10 months ago #3243

The code should not be entered in a php file but in the administration section of your Joomla installation in Components/RSForm!/<Your form> on the last tab scripts.

Grtz,


Cynthia
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is logged 15 years 10 months ago #3248

I did not enter it in a php file. I entered it via the admin in the script tab
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is logged in 15 years 9 months ago #3453

is this working at the end?
global $my;

if($my->id){
foreach($fields as $i=>$field){
if($field->name=='fullname') $fields[$i]->default_value = $my->name; //Assuming your rsform text field is called \"fullname\"
if($field->name=='email') $fields[$i]->default_value = $my->email; //Assuming your rsform email text field is called \"email\"
}
}

I’ve tried, but there is no value prefilled in the form...no error also
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is lo 15 years 9 months ago #3455

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
This code for J1.5 is the good one maybe, but it doesn't fonctionned
$my = &amp; JFactory::getUser();
if($my-&gt;id){
    foreach($fields as $i=&gt;$field){
        if($field-&gt;name=='fullname') $fields[$i]-&gt;default_value = $my-&gt;name; //Assuming your rsform text field is called \&quot;fullname\&quot;
        if($field-&gt;name=='email') $fields[$i]-&gt;default_value = $my-&gt;email; //Assuming your rsform email text field is called \&quot;email\&quot;
    }
}

Maybe this script is for RS!Form and not for RS!Form Pro

Into RS!Form Pro :
I make lot of try, and i see that the array called $fields, don't exist in function.php.
I try with the 3 array defined :
$find
$replace
$formLayout
but no one is fonctionned

I have modifed the script like this
$my = &amp; JFactory::getUser();
if($my-&gt;id){
    foreach($find as $i=&gt;$field){
        if($field=='{fullname:body}') {
              echo \&quot;$field $i\&quot;
              echo \&quot;$replace[$i]\&quot;
              echo \&quot;$formLayout[$i]\&quot;
    }
}


This part of the original script don't fonctionned with RS!Form Pro :
$fields[$i]-&gt;default_value = $my-&gt;name; //Assuming your rsform text field is called \&quot;fullname\&quot;

Answer of my test :
echo \&quot;$field $i\&quot;
I have the good answer of line and i see the good value and the line
echo \&quot;$replace[$i]\&quot;
I have the good answer of line but is preformated in string (80) \"<Input ....> and i show the input text
echo \&quot;$formLayout[$i]\&quot;
I have NOT the good answer but i see that the formLayout is like html code and is not an array when the script data on display is executed, so don't useful

My problem now is :
- find in the formlayout the good line
- how write my value into the good input, i try ajax, but it doesn't work

I don't know anything on php, but with search i find all this. If some RS!Form Team can help us, please, Alex ? :lol:

Monday, i have do a ticket for this and other script who doesn't fonctionned on Pro Version, i wait for the answer. If the team answer me i post the answer here.

Post edited by: dragonjc, at: 2008/06/24 23:25<br><br>Post edited by: dragonjc, at: 2008/06/24 23:26
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is lo 15 years 9 months ago #3468

  • benc
  • benc's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
I would like to know how to get this script working for RSformPro on J!1.5 too.

The provided scripts aren't populating the fields as described above.
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is lo 15 years 9 months ago #3479

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
<br><br>Post edited by: dragonjc, at: 2008/06/26 22:35
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is lo 15 years 9 months ago #3480

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
I have found (alone) a solution for this problem (for RS!Forms Pro) :

Solution, easier :) but after search a small :

How does it work ? Easy, Like this :

Assign an only crazy value like this one : *-*-* into the Default Value of the input you want pre-filled.

Now go to Script -> Script Called on form Display and paste

$my = &amp; JFactory::getUser();
if($my-&gt;id){
$formLayout = str_replace(\&quot;*-*-*\&quot;, $my-&gt;name, $formLayout);
}
Else {
$formLayout = str_replace(\&quot;*-*-*\&quot;, \&quot;Insert here your name\&quot;, $formLayout);
}

Explain of the script :
- I defined $my with the user information array
- If user is connected :
- I replace the defaut value by the value take of the row \"name\" from my array
- Else
- I replace the defaut value by the value of my choice


You don't want the user name ? Easy : change \"name\" from \"$my->name\" by another variable from this list :
id
name
username
email
password
usertype
block
sendEmail
gid
registerDate
lastvisitDate
activation
params

You want 2, 3,4, 5 pre filled value of this list ?
Easy :
$my = &amp; JFactory::getUser();
if($my-&gt;id){
$formLayout = str_replace(\&quot;-11-\&quot;, $my-&gt;name, $formLayout);
$formLayout = str_replace(\&quot;2-2*\&quot;, $my-&gt;username, $formLayout);
$formLayout = str_replace(\&quot;*3-3-*\&quot;, $my-&gt;email, $formLayout);
$formLayout = str_replace(\&quot;*4-4-4*\&quot;, $my-&gt;usertype, $formLayout);
}
Else {
$formLayout = str_replace(\&quot;*-11-*\&quot;, \&quot;Insert here your name\&quot;, $formLayout);
$formLayout = str_replace(\&quot;*2-2*\&quot;, \&quot;\&quot;, $formLayout);
$formLayout = str_replace(\&quot;*3-3-*\&quot;, \&quot;Insert here your email\&quot;, $formLayout);
$formLayout = str_replace(\&quot;*4-4-4*\&quot;, \&quot;\&quot;, $formLayout);
}

Don't forget to assign a value for your field default value who contain this pre filled, ans same for all the other one !

Have fun guys

Post edited by: dragonjc, at: 2008/06/26 20:13<br><br>Post edited by: dragonjc, at: 2008/06/26 22:35
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is lo 15 years 9 months ago #3493

  • benc
  • benc's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Thanks dragonjc, that last script works perfectly. B)
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is lo 15 years 9 months ago #3555

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
Hello everybody,

Update your Pro version, and try this :
www.rsjoomla.com/index.php/rsformpro.cus...n-form-is-shown.html

All is ok.
Spécial thank for Alex.
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is lo 15 years 9 months ago #3728

  • Bandit
  • Bandit's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
So if I want to fill a hidden RSformPro field called supplier (Joomla 1.5) with a user field from Community Builder called cb_supplier the code I need is....
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is lo 15 years 8 months ago #4383

  • adrian_m
  • adrian_m's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
I have 2 points from this thread. The first is that if I follow the link to http://www.rsjoomla.com/index.php/rsformpro.custom_code/Custom-code.html the instruction is:
1. Create a textbox component
2. In the Default Value, type this code:
//&lt;code&gt;
      $user = $RSadapter-&gt;user();
      return $user['email'];
      //&lt;/code&gt;

At first I could only enter one line of code in the default value field. I discovered users must add the UPDATE... problem solved!

My second point is that my site has just gone live and hit a massive problem which has completely confused me, but which could be related to RSForm Pro or, at least, the crazy character solution below. My form contains the following script (from here )
global $my;
if($my-&gt;id){
$formLayout = str_replace(\&quot;-11-\&quot;, $my-&gt;name, $formLayout);
$formLayout = str_replace(\&quot;2-2*\&quot;, $my-&gt;username, $formLayout);
$formLayout = str_replace(\&quot;*3-3-*\&quot;, $my-&gt;email, $formLayout);
$formLayout = str_replace(\&quot;*4-4-4*\&quot;, $my-&gt;usertype, $formLayout);
}
Else {
$formLayout = str_replace(\&quot;-11-\&quot;, \&quot;NOT REGISTERED\&quot;, $formLayout);
$formLayout = str_replace(\&quot;*2-2*\&quot;, \&quot;\&quot;, $formLayout);
$formLayout = str_replace(\&quot;*3-3-*\&quot;, \&quot;NOT REGISTERED\&quot;, $formLayout);
$formLayout = str_replace(\&quot;*4-4-4*\&quot;, \&quot;\&quot;, $formLayout);
}

The default value of the e-mail and username fields are as per the script. Also, the user e-mail is sent to {global:useremail}

Users A, B and C are in different countries and do not know each other.

User A logs in and completes a form. His form result appears to come from him, and he receives a confirmation e-mail.

While User A is still logged in, User B logs in and completes a form. User B's form displays user A's e-mail and username, and the confirmation e-mail is sent to user A.

While User A is still logged in, User C logs in and completes a form. User C's form displays user A's e-mail and username, and the confirmation e-mail is sent to user A.

The site is now offline and I am almost in tears, having already pulled out my hair. If anyone can suggest where this problem might be arising, please help, especially if it is connected with the form or script.

Thanks

Adrian

Post edited by: adrian_m, at: 2008/08/20 16:43<br><br>Post edited by: adrian_m, at: 2008/08/22 09:46
The administrator has disabled public write access.

Re:Pre-fill Name &amp; email address if user is logged in 15 years 4 months ago #5893

  • gags
  • gags's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi,

Im using 1.5.7 and RSForm.

I have added the script:

$my = & JFactory::getUser();
if($my->id){
foreach($fields as $i=>$field){
if($field->name=='Name') $fields[$i]->default_value = $my->name;
if($field->name=='E-mail') $fields[$i]->default_value = $my->email;
}
}


and it works perfectly except when the user is not logged in and then logs in from the same page that the form is on. Or if is logged in and then logs out from the same page that the form is on. I get a blank page with an \"Invalid Token\" on it.

Any ideas appreciated, Thanks
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 15 years 2 months ago #6458

  • kyr34
  • kyr34's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
$my=& JFactory::getUser();
if($my->id)
{ foreach($fields as $i=>$field){ 
if($field->name=='E-mail') $fields[$i]->default_value = $my->get('email');
if($field->name=='Name') $fields[$i]->default_value = $my->get('name'); 
}
}
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 15 years 1 month ago #6739

Setting the default value to {jos_name} doesn't work..it just sets the default to '{jos_name}'

The code above doesn't work either. I get an error every time. Does anyone actually have this working and can submit an actual solution for RSForm Pro?
Last Edit: 15 years 1 month ago by anthony.massa.
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 15 years 1 month ago #6854

Using the following code in the default value, I get the user name on the form, but it's not in the text box. It's at the top of the form?
//<code>
$user =& JFactory::getUser(); echo $user->name;
//<code>
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 15 years 1 month ago #6855

I Found A Way To Make It WORK!

First I installed the Sourcerer plugin found http://www.nonumber.nl/sourcerer. Enable the plug, and settings. Note under Advanced Parameters> Enable in components: Yes, and check mark RSForms Pro.
The Sourcerer plugin, us used to place code in articles, modules, and components.

Next RSforms Pro, Manage Forms> Components in the field default value enter this code:
 
{source}
<?php $user =& JFactory::getUser(); echo $user->name; ?>
{/source}
 

The back end preview you see the code in the element, but the front end you get the user name. This also works with the following fields:

id
name
username
email
password
usertype
block
sendEmail
gid
registerDate
lastvisitDate
activation
params

This also gives you a bigger range of options!
Check out this tutorial on adding more fields to the Joomla 1.5 Registration page: http://www.dart-creations.com/joomla/joomla-tutorials/adding-more-fields-to-the-joomla-registration-page.html. I added, phone, address, city, state, zip fields, and call them with the above method, and it pre fills the fields!!!
Last Edit: 15 years 1 month ago by RadVaWeasel.
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 14 years 8 months ago #8340

  • monashgk
  • monashgk's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
Joomla 1.5.14
RSFromPro! 1.2.0 rev 25

As a follow up to the last post anyone looking for an auto fill using Community Builder (CB), you can use the same plugin as above and the following code to insert any value from the jos_comprofiler table into a text field/textarea. Unfortunately I haven't got this working with dropboxes since there is no box to define the default value. Inserting the code on the first line just leaves you with a mess of code.

How to use:
1. Install the Sourcer plugin as per the post above
2. Create your textfield/area in RSFormPro.
3. Paste the below code into the 'Default value' box for the field. Note: {source} tags are defined in the sourcer plugin - if you leave it default this code will work as is.
4. Change 'cb_fieldname' on line 11 to the cb field you want to fill the form with.
{source}
<?php
global $database, $my;
$mydata = $my->id;
if($mydata!=0)
{
$data = "SELECT * FROM jos_comprofiler WHERE id = $my->id";
$result = mysql_query($data);
$info = mysql_fetch_array($result);
 
echo $info['cb_fieldname'];
}
?>
{/source}

If anyone has a solution for a dropbox it would be most appreciated.
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 14 years 7 months ago #8445

  • wsimpson
  • wsimpson's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
President,
Do you have this working? I can't seem to get this up and running. PHP seems OK but the database query seems to not be working right. Is there some permissions? I have installed the Sourcerer plugin and that seems to work fine but I get no data back into the field and no errors.
HELP PLEASE...
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 14 years 7 months ago #8518

  • monashgk
  • monashgk's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
OK since I made that post I have changed the code I am using.....

//<code>
global $my;
$myid = $my->id;
if ($myid > 0)
return @mysql_result(mysql_query("SELECT `cb_fieldname` FROM `jos_comprofiler` WHERE `user_id`='".$myid."' LIMIT 1"),0);
//</code>

Hope that works for you.
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 14 years 7 months ago #8519

  • monashgk
  • monashgk's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
Sorry....
//<code>
global $my;
$myid = $my->id;
if ($myid > 0)
return @mysql_result(mysql_query("SELECT `cb_memberid` FROM `jos_comprofiler` WHERE `user_id`='".$myid."' LIMIT 1"),0);
//</code>
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 14 years 6 months ago #8772

  • joseph.lalgee
  • joseph.lalgee's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 1
Although the previously submitted solution didnt work for me (edit: in RSForm Pro), the following did:
//<code>
$user = $RSadapter->user(); 
$myid = $user['id'];
if ($myid > 0) return @mysql_result(mysql_query("SELECT `cb_fieldname` FROM `jos_comprofiler` WHERE `user_id`=".$myid." LIMIT 1"),0);
//</code>

where cb_fieldname is the name you gave the field in community builder
Last Edit: 14 years 6 months ago by joseph.lalgee.
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 14 years 3 months ago #9468

  • mikebosh
  • mikebosh's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
Hi

Have followed instructions in field just get "<!-- Comment - Sourcerer: REMOVED ALL, NOT ENABLED -->" any idea what i am doing wrong


Thanks
Mike
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 13 years 9 months ago #10738

  • WillRoz
  • WillRoz's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Has anyone figured this out yet? Sourcerer is working OK, and I get no error messages, just the code showing in the front end of my form. Any suggestions please?
The administrator has disabled public write access.

Re:Pre-fill Name & email address if user is logged in 11 years 11 months ago #17258

  • sandstorm871
  • sandstorm871's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 1
RadVaWeasel wrote:
I Found A Way To Make It WORK!

First I installed the Sourcerer plugin found http://www.nonumber.nl/sourcerer. Enable the plug, and settings. Note under Advanced Parameters> Enable in components: Yes, and check mark RSForms Pro.
The Sourcerer plugin, us used to place code in articles, modules, and components.

Next RSforms Pro, Manage Forms> Components in the field default value enter this code:
 
{source}
<?php $user =& JFactory::getUser(); echo $user->name; ?>
{/source}
 

The back end preview you see the code in the element, but the front end you get the user name. This also works with the following fields:

id
name
username
email
password
usertype
block
sendEmail
gid
registerDate
lastvisitDate
activation
params

This also gives you a bigger range of options!
Check out this tutorial on adding more fields to the Joomla 1.5 Registration page: http://www.dart-creations.com/joomla/joomla-tutorials/adding-more-fields-to-the-joomla-registration-page.html. I added, phone, address, city, state, zip fields, and call them with the above method, and it pre fills the fields!!!
The administrator has disabled public write access.

Re: Pre-fill Name &amp; email address if user is logged in 11 years 11 months ago #17447

  • Bas103
  • Bas103's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I'm quite new here but i find that this is exactly what i need.

I have a Joomla 1.5.15 site with RSForm! (not the Pro version)
I have several forms on the site
everything is functioning fine,
But I would like the site to automaticly suggest (or fill) the user name and e-mail adres of the logged-in user
I find the code in previous post understandable,
but i can not figure out where i should put the code!
I tried almost every option in the form but nothing seems to work.

I installed the sourcerer plugin, but I can't find Advanced Parameters in the plugin so that line doesn't work for me

Please help me

Bas 103
Bas 103
The administrator has disabled public write access.

Re: Pre-fill Name &amp; email address if user is logged in 11 years 2 weeks ago #22396

  • MPRC
  • MPRC's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
This is exactly the issue I am having. I posted elsewhere for assistance too.
The administrator has disabled public write access.

Re: Pre-fill Name &amp; email address if user is logged in 11 years 2 weeks ago #22400

  • octavian
  • octavian's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 783
  • Thank you received: 110
You don't need any 3rd party extensions to do this. Please read this article
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.
The following user(s) said Thank You: thanos.lygdas
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!