The majority of the remainder of our ASP page is standard ASP code. For the purposes of the demo we have included three Order Numbers -
0,
999 and
1234 - but in a real application this code could be replaced by a call to a datasource to get the information instead. Thus the rest of our script looks as follows :
|
' Declare the variables
Dim inOrderNo ' Order Number entered by the user
Dim custName ' Customer Name
Dim custAddr ' Customer Address
Dim custPhone ' Customer Phone Number
Dim recFound ' Numeric Boolean indicating if we have found a record
' initalise the varaibles
inOrderNo=Request.Form("orderno")
custName=""
custAddr=""
custPhone=""
recFound=0
' populate the Customer Info according to the order number
if (inOrderNo=0) then
custName="Greg Griffiths"
custAddr="My House"
custPhone="123456789"
recFound=1
else if (inOrderNo=999) then
custName="John Doe"
custAddr="The White House"
custPhone="77 88 99 44"
recFound=1
else if (inOrderNo=1234) then
custName="Jane Doe"
custAddr="10 Downing Street"
custPhone="11 22 33 44 55"
recFound=1
end if
' send back the FDF Header
FDFHeader()
' send back the data if we have a valid record
if (recFound=1) then
call FDFValue("custname", custName & "")
call FDFValue("custaddr", custAddr & "")
call FDFValue("custphone", custPhone & "")
end if
' send back the return value
call FDFValue("retval", recFound & "")
' send back the FDF Footer
FDFFooter (request.servervariables("HTTP_REFERER"))
|
In the first section we declare all of the variables that we will need for our script, these include the Order Number, Customer Information fields and a flag to indicate if we have a successful match or not.
Now we need to set the inital values for these variables, we should have got the Order Number for what the user entered onto the form, so we can use the Request.Form object to get that, the Customer Information we will set to blank as a default value, and we set the value of our succesfull match flag to false.
We now need to process the provided Order Number and return the Customer information. For our demo we have hard coded the three Order Numbers, but in real life this could be a database lookup, we also set the match found flag as well.
Now we are ready to start sending information back to the client, so we start with the standard FDF Header.
If we have a successful match, then encode and send back the values for the Customer Information.
We will also send back the value of the flag - more on the reason for that later.
Finally, we close the output by sending back the FDF Footer.
|
If you now go back to the simple PDF Form and try entering values into the Order Number field, you should see that only when you enter one of the valid values does the form populate, otherwise you get a blank form.
We can now populate the content of textboxes on our PDF Form, the next challenge is to populate a dropdown list on the form.