Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 3 min read

Support

Motivation

You want to create a search form that uses a single input text field and submits a search request to a search service on a remote web server.

Discussion

We are all familiar with the simple front end to search engines like Google that display a simple search field. There are two simple features we will demonstrate in the first version. 1) The input cursor will be positioned in the search field when the form loads. When you press the "Enter" key the search will automatically be executed.

We will also discuss a way to have a single form display both simple search and complex search functions.

Method

We will first create a simple search input field and give it an id of "search-field". We will also add an action to the input that will fire off the submission when the Enter key is pressed.

ref="q" id="search-field">
Search string:
ev:event="DOMActivate">
submission="search"/>

In this example, q is a reference to the query string we will be sending to the remote server.

From the prior example we learned that you can have the cursor automatically positioned in the search field when the form loads by adding the following action added to your model:

...
ev:event="xforms-ready">
control="search-field"/>

...

Screen Image

Sample Google Search Form (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0)

Load XForms Application

Sample Program

In this example we will create a simple front end to Google's search engine. The format of the REST API for the Google search engine is the following:

google.com/search?hl=en&q=XForms

In this REST query the parameters are:

  • hl = language (en for English)
  • q = search query string

We can create an instance that has these parameters in our model:

xmlns="">

en

Full Program Listing

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events" >

Google Search Example
type="text/css">
body {font-family: Helvetica, sans-serif}

xmlns="" id ="search-params">

en

id="search-google" method="get"
action="http://www.google.com/search" replace="all"
separator="&"/>

ev:event="xforms-ready">
control="search-field"/>

Google Search Example
ref="instance('search-params')/q" id="search-field">
Search string:
ev:event="DOMActivate">
submission="search-google"/>

submission="search-google">
Search

Discussion

You can also send over a dozen other parameters to the Google search service. For example if you want to restrict
the search results to a specific web site or sub-site you can just add an additional "site" parameter that restricts search results to that site. For example the following URL will restrict the search results to pages on this wikibook:

google.com/search?hl=en&q=xforms+site%3Ahttp%3A%2F%2Fen.wikibooks.org%2Fwiki%2FXForms

Note that because forward slashes are part of the search query they are replaced with a %2F string.

The OpenSearch XML standard may also be of interest.
This standard allows any search service to specify the parameters to a search engine and how the data is returned to
a search client.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
XForms, Advanced Search
CC BY-SA 4.0
It must run from a webserver. To run this application you MUST enable XForms to submit data to other domains. In FireFox this is done by adding the domains to your trusted list. This can be done by going to the FireFox "Tools" menu, selecting Preferences, selecting the "Content" tab, and adding the
CC BY-SA 4.0
Web services can be called directly from an XForms application using the **submission** element in the model. ## Connecting a web service to an Event To call a web service you first need to "wire it" up to an event. For example this can be a "submit" button at the end of a form. The submit element i
CC BY-SA 4.0
XForms, Search Amazon
CC BY-SA 4.0
- Uncompress the zip file on your local file system - Change any occurrences of **"&"** to **& a m p ;** and remove **& n b s p ;** and **& c o p y ;** in the HTML files to make the files well formed XHTML files so that eXist can index them. The following files in the 3.2 release will need to be mod
CC BY-SA 4.0
This updates the visible image. Note that the output must have a the mediatype set to be **image/*** for the browser to render the link as an image correctly. ## Attribution This example was created by Chris Wallace and the University of Western England.