• 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: global variables in forms

global variables in forms 17 years 5 months ago #1358

  • ron
  • ron's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
I have a question on how to use RSForms for an Ask The Expert piece I am working on.

I have a site where I have a one page for each \"expert.\"
On this page I have added a form called \"Ask The Expert\" (I am using the {mosforme} plugin.
I want to create one Ask The Expert form but use it on several Expert pages.
When the user fills out the information is there a way I can capture the experts name from the page. The Title of the page is the experts name. So if there is a page title variable or something that I can capture and save with the form and send with the email, that would be perfect. I just don't know how to do this.

One other question is when they click submit how do I return them to the page where they were before submitting the Ask The Expert form?

Any help will be greatly appreciated.

Ron
The administrator has disabled public write access.

Re:global variables in forms 17 years 5 months ago #1385

  • alex
  • alex's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 443
  • Thank you received: 3
Hello Ron,

from what I understand you used the rsform mambot in order to attach it to the article. Edit the form, and add a new field(field type=hidden,field id=contenttitle) and another one(field type=hidden,field id=returnurl).

In the Scripts tab, in Scripts called on form display, type this script:
global $mainframe;
foreach($fields as $i=>$field){
  if($field->name=='contenttitle'){
      $fields[$i]->default_value = $mainframe->_head['title'];
  }
   if($field->name=='returnurl'){
       $fields[$i]->default_value = $_SERVER['REQUEST_URI'];
   }
}
Then go to the main tab, and in the Return URL field, type {returnurl}

You will see the field contenttitle populated with the content title in the backend and you can use {contenttitle} in your email .
The administrator has disabled public write access.

Re:global variables in forms 17 years 4 months ago #1606

  • khellus
  • khellus's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
French and Newbie :

Where is the Scripts tab, in Scripts called on form display ?

I dont understand...
The administrator has disabled public write access.

Re:global variables in forms 17 years 3 months ago #1689

  • alex
  • alex's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 443
  • Thank you received: 3
Hi Khellus,

edit your form, and on the top-left side, you'll see the tabs:
Form Edit
Form Style
Thank You
Emails
Scripts

Click on Scripts, and you will see 2 textboxes. Scripts called on form display and Scripts called on form process.

Alex.
The administrator has disabled public write access.

Re:global variables in forms 17 years 1 month ago #2492

This is exactly what I needed and the main reason I decided to purchase this Joomla! extension. I managed to get it set up and working as described here. Thanks!

To summarize what I did:
  • I added (field type=hidden,field id=returnurl) to my form
  • I added (field type=text,field id=contenttitle) I wanted this one visible
  • I added this script in the Scripts tab/Scripts called on form display box:
global $mainframe;
 
foreach($fields as $i=>$field){
 
  if($field->name=='contenttitle'){
 
      $fields[$i]->default_value = $mainframe->_head['title'];
 
  }
 
   if($field->name=='returnurl'){
 
       $fields[$i]->default_value = $_SERVER['REQUEST_URI'];
 
   }
 
}

Just one question: I'm using a single form for quote requests on multiple products. The form is returning the page title so I know which product is being requested. I put the field id=contenttitle in a visible text field so the user can see what product is being referred to by the form. But it returns the entire page title, not just the product name, like this - \"Clawfoot Tubs Online - American Bath Factory Princess\".

I would like to strip out the \"Clawfoot Tubs Online - \" part and just return \"American Bath Factory Princess\". This should be possible with code, but I don't know PHP or javascript well enough to figure it out.

Any ideas?

Thanks in advance,
Richard
The administrator has disabled public write access.

Re:global variables in forms 17 years 2 weeks ago #2844

  • trevort
  • trevort's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I am trying to do almost exactly the same thing but I'm not having any luck.

I have a small form for users to upload a resume and coverletter to apply for postings online. I am using the same form in the bottom of all the postings by way of the mosforme plugin. {mosforme 1}

I added the contenttitle field with just the ID, and type (text) as well as adding the script below to the 'Scripts called on form display':
global $mainframe;
foreach($fields as $i=>$field){
  if($field->name=='contenttitle'){
      $fields[$i]->default_value = $mainframe->_head['title'];
  }
}

I dont get anything returned however. Am i missing something simple?
The administrator has disabled public write access.

Re:global variables in forms 16 years 11 months ago #3057

  • trevort
  • trevort's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
anyone?
The administrator has disabled public write access.

Re:global variables in forms 16 years 10 months ago #3621

  • lownotes
  • lownotes's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Thank you received: 1
Are these instructions still valid for J1.5?
I've set everything as instructed on this thread but I don't seem to be getting any data sent back for the variable value. It's just blank. I'm guessing the script might not be processing.

Any help would be great!

Thanks.
The administrator has disabled public write access.

Re:global variables in forms 16 years 9 months ago #3709

  • Corossi
  • Corossi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
lownotes wrote:
Are these instructions still valid for J1.5?
I've set everything as instructed on this thread but I don't seem to be getting any data sent back for the variable value. It's just blank. I'm guessing the script might not be processing.

Any help would be great!

Thanks.

I've got the same problem, it doesn't seem to work for me neither.
Also tried it with a SQL query, but the field stays blank.
The administrator has disabled public write access.

Re:global variables in forms 16 years 9 months ago #3710

  • haboyes
  • haboyes's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
There appears to be a problem with using this in J1.5.3
global $mainframe;
foreach($fields as $i=>$field){
   if($field->name=='returnurl'){
       $fields[$i]->default_value = $_SERVER['REQUEST_URI'];
   }
}

Inserting the above text into the \"on before display\" box on the scripts tab yields the following error message on the form:
\"Warning: Invalid argument supplied for foreach() in ...\com_rsforms\controller\functions.php(847):eval()'d code on Line 2\"
The administrator has disabled public write access.

Re:global variables in forms 16 years 9 months ago #3719

  • Corossi
  • Corossi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
haboyes wrote:
There appears to be a problem with using this in J1.5.3
global $mainframe;
foreach($fields as $i=>$field){
   if($field->name=='returnurl'){
       $fields[$i]->default_value = $_SERVER['REQUEST_URI'];
   }
}

Inserting the above text into the \"on before display\" box on the scripts tab yields the following error message on the form:
\"Warning: Invalid argument supplied for foreach() in ...\com_rsforms\controller\functions.php(847):eval()'d code on Line 2\"

I get the same error when using that script...
The administrator has disabled public write access.

Re:global variables in forms 16 years 9 months ago #3840

  • jhellein
  • jhellein's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Me three! (I get that same error on the form in 1.5). Please help!
The administrator has disabled public write access.

Re:global variables in forms 16 years 9 months ago #3878

I'm using the pro version in joomla 1
have the same problem
The administrator has disabled public write access.

Re:global variables in forms 16 years 4 months ago #6059

Just wanted to post something related that helped me insert name, username, and email:
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;
   }
}
The administrator has disabled public write access.

Re:global variables in forms 16 years 1 month ago #6821

where do you put this code?

what do I need to update inorder to have this work with my form. I can't seem to figure it out.

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!