How do I pass a parameter through the URL and how can I catch it ?

Parameters can be added in the URLs that direct to form pages. Using these parameters, you can customize your form to automatically add them as default values for its fields and further use these values in various manners. We will split this article in 2 sections, first part using the RSForm!Pro specialized URL syntax and the second part, using a custom code.

RSForm!Pro URL syntax

RSForm!Pro introduces a simple and easy to understand syntax that allows assigning default values to form fields through URL parameters:

http://www.mywebsite.com/index.php?option=com_rsform&formId=1&form[name_of_field]=value

Depending on the field type, the syntax will differ slightly:

Textbox, textarea, single select lists (radio groups)

Let's assume that that you wish to pass, to your form's email field, the mail@domain.com value. The URL will need to look like this:

http://www.mywebsite.com/index.php?option=com_rsform&formId=1&form[email]=mail@domain.com

Multiple select lists (checkbox group, dropdown)

In this situation, the syntax for the URL parameter will differ a little bit, as you need to specify which of the already existing (multiple) items need to be selected. Assuming that your multiple select list field is called staff, having the following items (specified in its configuration):

    John Doe
    Nancy Williams
    Mike Johnson
    Jennifer Robinson

and that you wish to have John Doe and Jennifer Robinson selected, your URL should look like this:

http://www.mywebsite.com/index.php?option=com_rsform&formId=1&form[staff][]=John Doe&form[staff][]=Jennifer Robinson


Note:

This syntax will not work for hidden fields. In such cases you can either, use the last method from this article or use a regular textbox which can be hidden through inline CSS by adding style="display:none;" as an Additional Attribute (edit the textbox > Attributes > Additional Attributes).

IMPORTANT:

  • If the parameter you are adding is the first one existing in the URL (when using SEF URLs), you need to add it using the ? character instead of &, as in the following example:

    http://www.mywebsite.com/index.php/form?form[email]=mail@domain.com

  • You need to use the select list items' values in the syntax, not their captions.
Birthday field

The Birthday Field requires a special syntax, through which you can specify the day, month and year:

http://www.mywebsite.com/index.php?option=com_rsform&formId=1&form[name_of_field][d]=15&form[name_of_field][m]=07&form[name_of_field][y]=1993

The form's URL, as written above, will transmit the 15th of July 1993 date to the birthday field.

Note: You do not necessarily need to use leading zeros when specifying the day and month. If, for example, you need to pass the month of April, you can do so using both the 4 and 04 values, the result will be the same.

 
Custom approach

Let's take the following example:

www.mywebsite.com/index.php?option=com_rsform&formId=1&myparameter=myvalue

In "Default Value" field of the form component you can add any PHP code you want. Just remember that the <code> tag is mandatory. Below you can find an example:

    //<code>
    return Joomla\CMS\Factory::getApplication()->input->getString('myparameter');
    //</code>
Implementation:

The "Display information submitted in a different form" article provides an example on how this can be useful.


66 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

Mapping submission info to other database tables HOT

Recording the referer page HOT

How do I display the current URL HOT