Yahoo! Application Platform (YAP) search box code example

Want to add a search box to your Yahoo application (YAP app)? Here’s some sample PHP code to help you get started. It consists of a single file that calls itself to perform a search and output the results. If the file is requested without a search_term parameter, it will output a form consisting of:

yml:form tags defining a form that will make an asynchronous Get request when submitted. Because no param attribute is defined for the yml:form tag, it will call back to the application URL by default. The replace attribute specifies that output of the callback file will replace a DOM element in the app with the id matching the value of the attribute, which in this example is “results”.

an input field and submit button

When the form submits back to this file with the search_term defined, the file outputs HTML for an unordered list containing the results of a search. This HTML is then placed on the page by the yml:form tag.

Prerequisites

PHP 5.2

A server that’s accessible to YAP, i.e., a server with a valid domain name and capable of receiving POST requests. For this example, I’ll assume the domain name is example.com.

A YAP application. If you don’t have one already, you can create one using the YDN dashboard.

Usage

1. Put the code below into a file on your server. For this example, I’ll use the file name file.php.
2. In the YDN dashboard, set the Application URL to the location of the file you created in step 1, e.g., http://example.com/file.php.
3. Preview the app by clicking the Preview button in the dashboard.

4. In the app’s text field, enter a search term, e.g., “pizza”, and click the Search button.
5. View the search results when they appear below the text field.