Setting Up an .Asp Form

In an .asp query, you need to first create the header and then the form.

This section contains:

Setting Up the Header

You begin by setting up header information, as you did when creating the .htm form in the previous test drive. The <SCRIPT LANGUAGE> and </SCRIPT> turn scripting on and off. This example is turning on a Visual Basic Scripting command, option explicit.


<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN" "html.dtd">
<HTML>
<HEAD>

    <SCRIPT LANGUAGE="VBScript" RUNAT="Server">
    <!--
        option explicit
      -->
    </SCRIPT>

    <TITLE>Index Server Search Form</TITLE>

    <META NAME="DESCRIPTION" CONTENT="Sample ASP query form for 
                Microsoft Index Server">
    <META NAME="KEYWORDS"    CONTENT="query, content, hit, asp">
    <META NAME="MS.LOCALE"   CONTENT="EN-US">
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; 
                charset=Windows-1252">

In the preceding HTML code, the bold type contains a sampling of meta tags:

Description
Sets the abstract that a client sees in the query results.

Keywords
Lists keywords a client can search for in a query.

MS.Locale
Sets the language code for this form. EN-US stands for American English. For a complete list of supported language codes, see Valid Locale Identifiers.

Content Type
Determines the character set (charset) used. In this example, the Roman alphabet as opposed to Kanji. For a complete set of supported tags, see Recognized Character Set Tags.

The next section turns form variables into server-side VBScript variables. The actual query form appears later in the file. Positioning the form data here allows the form fields to be pre-initialized, which causes the text of your query to reappear in the form field after the query results are displayed.


<%
    NewQuery = FALSE
    UseSavedQuery = FALSE
    QueryForm = Request.ServerVariables( "PATH_INFO" )
    SearchString = ""
    if Request.ServerVariables("REQUEST_METHOD") = "POST" then
        SearchString = Request.Form("SearchString")
        pg = Request.Form("pg")

        if pg <> "" then
           NextPageNumber = pg
           NewQuery = FALSE
           UseSavedQuery = TRUE
        else
            NewQuery = SearchString <> ""
        end if
     end if

 %>
</HEAD>

Also, the line in bold type defines the query form as the current file, in this case, Ixtrsasp.asp. From now on, the sample files is referred to as QueryForm. This line allows you to change the name of the sample file without having to change the name anywhere within the file.

Creating the Form

Now you are ready to create the search form.


<TABLE>
    <TR>
        <TD><IMG SRC ="is2logo.gif" VALIGN=MIDDLE ALIGN=LEFT></TD> 
        <TD><H1>Sample ASP Search Form</H1></TD>
    </TR>
</TABLE>

<HR WIDTH=75% ALIGN=center SIZE=3>
<p>

<TABLE>
  <TR>
    <TD ALIGN=LEFT>Enter your query below:</TD>
  </TR>
  <TR>
    <TD>
      <FORM ACTION="<%= QueryForm%>" METHOD=POST>

        <TABLE>
          <TR>
            <TD><INPUT TYPE="TEXT" NAME="SearchString" SIZE="60"
                         MAXLENGTH="100" VALUE="<%=SearchString%>"></TD>
            <TD><INPUT TYPE="SUBMIT" NAME="Action" VALUE="New Query"></TD>
          </TR>
        </TABLE>
       
      </FORM>
    </TD>
  </TR>
</TABLE>

As with the .htm form, the two most important lines are the FORM ACTION and the INPUT TYPE lines.

<FORM ACTION. . .>
Instead of naming an .idq file, this line names the current file, where the .idq processing code is located.

<INPUT TYPE="TEXT". . .>
Notice the different syntax in the .asp file. Here the variable SearchString, rather than CiRestriction, is preset to accept whatever text is typed in the Enter your query below field. For example, if you type cache in this field, SearchString holds the text cache.

<INPUT TYPE="SUBMIT". . .>
This line creates the button that executes your query. In this example, the button is called New Query.

© 1997 by Microsoft Corporation. All rights reserved.