Pass values to a form in order to dynamically change its content / layout
Semantic extension(s): | Page Forms |
Further extension(s): | -/- |
Keyword(s): | -/- |
Description:
In order to make a form dynamic, it's necessary to pass values into the form that can be evaluated by parser functions. Since this is not possible with Semantic Forms itself (you can only pass values that go into the form fields, see [1]), another extension is needed: the UrlGetParameters extension, which provides the {{ #urlget: ... }}
parser function.
Note that this tip is only useful for making a form dynamic on the first use (when creating a page) - via a special link provided to the user. It is not possible to have the form customised on later edits.
So once UrlGetParameters is installed on your Wiki, you can make your form dynamic - here is an example:
Lets say you have a Wiki about cars and you want to put a link to create a new car page (formlink, see [2]) that does not show the part of the form that is only relevant for utility vehicles, because in the context of that formlink, the user would only want to create a page about a passenger car. To achieve this, wrap the utility vehicle section of the form in a
{{ #ifeq: {{ #urlget: DisableUtilityPart|false }} | true | ... }}
parser function call. The formlink that opens the form with the utility vehicle section disabled would then look like
{{ #formlink: Car|New passenger car page|link|Car[Class]=passenger&DisableUtilityPart=true }}
Note that the parameter DisableUtilityPart with the value true (highlighted with green background colour) goes into the query_string part of the formlink - in this example it is appended to the preload statement that automatically fills passenger into the field Class of the template Car (highlighted with yellow background colour).
This tip does not work when the third parameter of the #formlink is "post button", since the parameters are then handed to the form via a POST request, while UrlGetParameters can only handle GET requests.