• 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: Passing global variables?

Passing global variables? 17 years 4 months ago #1535

  • oellison
  • oellison's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Hello,
Would it be possible to get such global variables as, for example, userid of who submitted the form, in place of asking the users to re-enter their information? The purpose of this would be to trace each a form to a user.
The administrator has disabled public write access.

Re:Passing global variables? 15 years 9 months ago #8204

  • demitra
  • demitra's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi,
I have the same question, I have found "almost" the answer in other posts but not quite as it leads me to errors. This is what i understand so far:

I want to also add some info from the user without asking him (if he is indeed logged into my site)
His email address/name/user name

In a post i found that i am to use this
global $mainframe;
foreach($fields as $i=>$field){
   if($field->name=='username'){
       $fields[$i]->default_value = JFactory::getUser()->username;
   }
   if($field->name=='name'){
       $fields[$i]->default_value = JFactory::getUser()->name;
   }
   if($field->name=='email'){
       $fields[$i]->default_value = JFactory::getUser()->email;
   }
}

I putthe above in scripts called on form display

Then created a 3 separate hidden fields each with the names:
username / name / email
and added to to my email form

but when I go to the form, I get this
Warning: Invalid argument supplied for foreach() in /home/.../public_html/components/com_rsform/controller/functions.php(836) : eval()'d code on line 2

Rather than putting something in the scripts section, should i be putting something in the default values of each hidden field instead?

How do you actually get global variables into a hidden field (more specifically name/username/email)

Thank you!!!

(Sorry just realized im in the rsform forum but I am using PRO! )
Last Edit: 15 years 9 months ago by demitra.
The administrator has disabled public write access.

SOLVED Re:Passing global variables? 15 years 9 months ago #8254

  • demitra
  • demitra's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
The lovely Bogdan gave me the answer so I thought I would share it in this post. This is for RSForm! Pro only.

In order to capture user information with RSForm! Pro you can create a hidden field in your form for each information you want to get (1 hidden field for email, another one for username and another one for name). Let's assume that the fields are called like this: User1 (for the field that captures the username), User2(for the field that captures the name) and User3(for the field that captures the email). Then you can paste the following code in the "Scripts called on form process" area:

$rsuser =& JFactory::getUser();
$myemail = $rsuser->email;
$myuser = $rsuser->username;
$myname = $rsuser->name;
$_POST = $myemail;
$_POST = $myname;
$_POST = $myuser;

Note that you can change the field names for your form, but please remember to change the names in their respective code lines from the script also. So if you want to change the 'User3' field name to 'UserEmail' you will have to change this line:

$_POST = $myemail;

to this:

$_POST = $myemail;
The administrator has disabled public write access.

Re:Passing global variables? 14 years 11 months ago #10576

This worked perfectly for me.

Thanks!
The administrator has disabled public write access.
  • 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!