Extension:Page Forms/Creating query forms

From MediaWiki.org
Jump to: navigation, search
Page Forms - navigation (viewTemplate:Page Forms navigation)
Basics Main pageExtension:Page Forms (talk) · Download and installationExtension:Page Forms/Download and installation · Quick start guideExtension:Page Forms/Quick start guide · HostingExtension:Page Forms/Hosting · Special pagesExtension:Page Forms/Special pages
Using Page Forms PF and templatesExtension:Page Forms/Page Forms and templates · Defining formsExtension:Page Forms/Defining forms   (Input typesExtension:Page Forms/Input types) · The "Edit with form" tabExtension:Page Forms/The "edit with form" tab · Linking to formsExtension:Page Forms/Linking to forms · Creating query formsExtension:Page Forms/Creating query forms
Resources for help Common problemsExtension:Page Forms/Common problems · Known bugs and planned featuresExtension:Page Forms/Known bugs and planned features · Getting supportExtension:Page Forms/Getting support · Developers' documentationExtension:Page Forms/Developers' documentation · TestingExtension:Page Forms/Testing
About Page Forms Authors and creditsExtension:Page Forms/Authors and credits · Version historyExtension:Page Forms/Version history · Sites that use Page FormsExtension:Page Forms/Sites that use Page Forms · Related extensionsExtension:Page Forms/Related extensions

Forms can also be used for querying, as opposed to adding or editing data. To do so, use the Special:RunQuery page, which displays a form in a manner similar to Special:FormEdit, but with no associated 'target page'. Instead, when the user submits the form by hitting the "Run query" button, they see what the template looks like when displayed with the values they entered.

The template that the form uses should most likely contain one or more queries (using Semantic MediaWiki inline queries, Cargo queries, External Data queries, etc.) to query data using values that the user entered. You can see an example of a query form here.

The "Run query" button[edit]

By default, a button called "Run query" shows up at the bottom of forms if they are accessed via Special:RunQuery. You can change the location and text of this button, using the tag "{{{standard input|run query}}}" (or "{{{standard input|run query|label=...}}}", etc.) within the form definition.

See Defining forms#"standard input" tag for more information.

Query form at top[edit]

If you add the parameter "query form at top" to the {{{info}}} tag, the query input field will show up at the top of the results page, instead of the bottom.

Creating links to query forms[edit]

Once a query form has been created, you can link to it using syntax that looks like this:

[[Special:RunQuery/query form name]]

However, the preferred solution, because it's easier and more powerful, is to use the #queryformlink parser function. A basic call to that function would look like:

{{#queryformlink:form=query form name}}

Here's the complete syntax of #queryformlink:

{{#queryformlink:form=|link text=|link type=|query string=|query string parameters|tooltip=|popup}}

These parameters are almost identical to the ones used by #formlink; for a full explanation of the parameters, see Using #formlink.

Embedding query forms[edit]

You can also embed a query form within another page. To do that, add the following in a page where you want the query form to appear:

{{Special:RunQuery/query form name}}

Preloading data in the query[edit]

In case query data needs to be pre-loaded, the Special:RunQuery should follow the convention


For example, like this:


The construction item-name might cause a problem in connection with the wiki markup, and therefore the square brackets— [ and ]—can be replaced with either %5B and %5D, or [ and ]).

Finally, make sure that the case in the query string matches the declaration in the form (e.g., {{{for template|Item_query}}} must match ?Item_query[author]=John and {{{for template|item_query}}} must match ?item_query[author]=John.

Alternatively, you can preload data by using the default= parameter for form fields.

You can also link to Special:RunQuery where the query has already been run. To do that, just add "wpRunQuery=true" to the query string; see here for an example.

As before, the recommended way to link to such a page is with #queryformlink.