Selective Data Acess

In our next example somecust.afp we want to limit the number of customers displayed by specifying their initial. To this end, we expand our previous example with an input option for the search key and limit our request to that search key:

<HTML>

<HEAD>

  <TITLE>Some customers of table CUSTOMER</TITLE>

<HEAD>

 

<BODY>

  <h1 color="#0000FF">Some customers of table CUSTOMER</h1>

  <hr>

  <form method="POST" action="somecust.afp">

    <p>Please specify the starting letter:

      <input type="text" name="searchkey" size="5">

      <input type="submit" value="Request" name="B1"></p>

  </form>

 

  <table border="1" width="95%">

    <tr bgcolor="#808080">

      <td width="20%">cust_id</td>

      <td width="40%">company</td>

      <td width="40%">contact</td>

    </tr>

    <%

      if not used("customer")

        use File.FullPath("data\customer.dbf") in 0

      endif

 

      select customer

      lcsearchkey = upper(Request.Form("searchkey"))

 

      if empty(lcsearchkey)

        lcsearchkey=" "

      endif

 

      scan for cust_id = lcsearchkey

      <%

      </tr>

        <td><% ? customer.cust_id %></td>

        <td><% ? customer.company %></td>

        <td><% ? customer.contact %></td>

     </tr>

     %>

     endscan

   %>

  </table>

<BODY>

<HTML>

At the first invocation of the page no customer dates will be returned, as no search key has been entered. Once the search key is entered, a request of all customer data will be run. It will return the desired result.

In order for Visual FoxPro to know which data should be searched on the basis of the input on our form, in this example we use the system function Request.Form("searchkey"). This function returns the value of the input field. Here, the term "searchkey" corresponds to the name we assigned to the input box <input ... name="searchkey"> within the <form> tag.