• 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: Set form field via URL

Set form field via URL 9 years 2 months ago #30159

Hello,
is it possible to fill some form values via URL, like in RSFromPro "?form[Subject]=text for subject field"?
The administrator has disabled public write access.

Set form field via URL 9 years 2 months ago #30164

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Although there is no built-in solution for this, you can use the module's Javascript section to achieve that result.

Step1
head over to the Form Options and in the Javascript section paste the following JS snippet
function getUrlParameters(parameter, staticURL, decode){
   /*
    Function: getUrlParameters
    Description: Get the value of URL parameters either from 
                 current URL or static URL
    Author: Tirumal
    URL: www.code-tricks.com
   */
   var currLocation = (staticURL.length)? staticURL : window.location.search,
       parArr = currLocation.split("?")[1].split("&"),
       returnBool = true;
 
   for(var i = 0; i < parArr.length; i++){
        parr = parArr[i].split("=");
        if(parr[0] == parameter){
            return (decode) ? decodeURIComponent(parr[1]) : parr[1];
            returnBool = true;
        }else{
            returnBool = false;            
        }
   }
 
   if(!returnBool) return false;  
}

Step 2

grab your field's ID from the front-end (through the use of developer tool such as firebug)

Step 3

Head over to Form Options and use the following code (place it after the snippet you saved before)
jQuery('document').ready(function(){
 
	var customParameter = getUrlParameters("custom", document.URL, true); // grab the parameter, change "custom" to the parameter that you are using.
	jQuery('#id_of_field').val(customParameter); //change the value of the field with the retrieved parameter
 
});
Simple and clean.
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.

Set form field via URL 9 years 2 months ago #30166

Thank you for your reply. It almost works, only one issue: if no parameter is passed over the URL, there's JS error and some JS scrips on site also fail because of that. Any way to fix that?
The administrator has disabled public write access.

Set form field via URL 9 years 2 months ago #30187

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Might be a crude fix, however it gets the job done.

Use this instead:
jQuery('document').ready(function(){
	var url 	= document.URL; // we grab the url
	var urlCheck 	= url.indexOf('custom') > -1; // check to see if we have the parameter
 
		if (urlCheck){ // if statement true , run
			var customParameter = getUrlParameters("custom", "", true);
			jQuery('#id_of_field').val(customParameter);
		}
 
});
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 9 years 2 months ago by cosmin.cristea.
The administrator has disabled public write access.

Set form field via URL 9 years 2 months ago #30188

Thank you, works nicely.
The administrator has disabled public write access.

Set form field via URL 9 years 2 months ago #30190

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
You are welcome, if you encounter any other issues do not hesitate to ask here!
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.

Set form field via URL 9 years 2 months ago #30275

Why not just put a little PHP code in the default vaule of the field, like:
//<code>
$field = JRequest::getVar('custom');
return $field;
//</code>
The administrator has disabled public write access.

Set form field via URL 9 years 2 months ago #30282

  • octavian
  • octavian's Avatar
  • NOW ONLINE
  • RSJoomla! Official Staff
  • Posts: 783
  • Thank you received: 110
Because this isn't RSForm! Pro :)
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.
  • 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!