Create a dynamic form search with radio buttons
Create a dynamic form search with radio buttons
You can create a dynamic form search that is populated using radio buttons. You specify a search to populate radio button choices. A user selects a radio button drive the search results.
Dynamic form search example
1. Use a simple form search to get started.
<form>
<label>Username</label>
<searchTemplate>sourcetype=logins $username$</searchTemplate>
<fieldset>
<input type="text" token="username" />
</fieldset>
<row>
<event>
<option name="count">100</option>
</event>
</row>
</form>
2. Change the input from a text box to radio buttons. Add a <populatingSearch> to generate the options for the radio buttons
. . .
<input type="radio" token="username">
<label>Select Name</label>
<populatingSearch fieldForValue="suser" fieldForLabel="suser">
<![CDATA[sourcetype=p4change | rex "user=(?<suser>\w+)@"
| stats count by suser]]>
</populatingSearch>
</input>
. . .
3. Display the results in a table. The following is the complete dynamic form search.
<form>
<label>Username</label>
<searchTemplate>sourcetype=logins $username$</searchTemplate>
<input type="radio" token="username">
<label>Select Name</label>
<populatingSearch fieldForValue="suser" fieldForLabel="suser">
<![CDATA[sourcetype=p4change | rex "user=(?<suser>\w+)@"
| stats count by suser]]>
</populatingSearch>
</input>
<row>
<table>
<title>Users</title>
<option name="showPager">true</option>
</table>
</row>
</form>
Radio button configuration options
There are several configuration options available for <input type="radio">.
| Tag | Description |
|---|---|
<label>label</label> | A label for the radio buttons. |
<default>option</default> | The default option to select. If the default option cannot be found, the first option is selected. |
<prefix>search terms</prefix> | Prefix the search query with the specified search terms. |
<suffix>search terms</suffix> | Place the specified search terms after the search query. |
<choice value="value"> | Specify options for radio buttons. Options appear in the order they are defined, and before any options generated by a search specified by <populatingSearch>.
|
<populatingSearch fieldForLabel="label" fieldForValue="value"> | A search that generates options for the radio buttons. Requires the attributes fieldForValue and fieldForLabel. fieldForValue is the field extracted from the populatingSearch and placed in the value of the generated radio button option. fieldForLabel is the field extracted from the populatingSearch and placed in the label of the generated radio buttons.
|
<populatingSavedSearch fieldForLabel="label" fieldForValue="value"> | A saved search that generates options for the radio buttons. Requires the attributes fieldForValue and fieldForLabel. fieldForValue is the field extracted from the populatingSavedSearch and placed in the value of the generated radio button option. fieldForLabel is the field extracted from the populatingSavedSearch and placed in the label of the generated radio buttons.
|
<earliestTime>Splunk time format</earliestTime> | Restrict your search results to a specific time window, starting with the earliestTime. Specify "rt" to enable realtime searches. |
<latestTime>Splunk time format</latestTime> | Restrict your search results to a specific time window, ending with the latestTime. Specify "rt" to enable realtime searches. |
This documentation applies to the following versions of Splunk: 4.3 View the Article History for its revisions.
The third example is missing the tags around the input section.