Yahoo! Developer Network Blog

« Previous | Main | Next »


November 24, 2009

Yahoo! Application Platform (YAP) search box code example

Putting a search box in your YAP app

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.

Code



See the code on github

---

Erik Eldridge

Yahoo! Developer Network

Posted at November 24, 2009 6:37 PM | Permalink

Bookmark this on Delicious

Comments

I need a completeI idoit's guide on this subject. CAN somebody help me????

Posted by: Buzz young at December 12, 2009 3:08 PM

Hi Buzz,

The Yahoo! Application Platform (YAP) documentation has a nice "getting started" tutorial you may find helpful:
http://developer.yahoo.com/yap/guide/creating_open_app.html

You can ask technical questions on the YAP forums:
http://developer.yahoo.net/forum/index.php?showforum=40

Posted by: Erik at December 14, 2009 2:42 PM

@Robert

You can register a new app by clicking the "MY PROJECTS" link in the header above. If you're not signed in, you'll be redirected to a sign in page. If you don't have a Yahoo! account, you can create one from the sign in page.

Posted by: Erik at February 5, 2010 10:42 AM

i like it

Posted by: kathy lovenburg at February 8, 2010 1:39 PM

Post a comment

Comment Policy: We encourage comments and look forward to hearing from you. Please note that Yahoo! may, in our sole discretion, remove comments if they are off topic, inappropriate, or otherwise violate our Terms of Service. Fields marked with asterisk '*' are required.

Remember Me?

Subscribe

YDN Blog: Get Yahoo! Developer Network Blog on your personalized My Yahoo! home page.

Add To My RSS Feed

YDN Link Blog: Get Yahoo! Developer Network Linkblog on your personalized My Yahoo! home page.

Add To My RSS Feed

Recent Readers

Copyright © 2010 Yahoo! Inc. All rights reserved. Copyright | Privacy Policy

Help us continue to improve the Yahoo! Developer Network: Send Your Suggestions