Q. How do I gather data from a form and send the output to a file ?

A. You will need to do three things to set up the process to gather data from a form and write it to a file.

  1. Create a form and use the program yform to process the data.

    The datafile that receives the output from the form can not reside in your www account directory. If the file is there, anybody could read your information. So, a separate area is set aside for your account to receive the output that is secured from the public. That area has the tree name :

    /home/yformusers/account-name/
    
    For example, if your account is masters, then your tree name is

    /home/yformusers/masters
    
  2. Create the datafile to receive the output from the form. Sign onto the institutional web server using your account and password. Next enter the appropriate directory and create a zero-length filename. This filename must match the name you use in the form.
    cd /home/yformusers/account-name
    touch filename
    
    In this case,
    cd /home/yformusers/masters
    touch database.txt
    
  3. Change the permissions on the file that you just created.
    chmod a+w filename
    
    In this case,
    chmod a+w database.txt
    
To collect the data, you can get the data file using WS_FTP and download it to your PC for processing. Recall the path to the file that you created :
/home/yformusers/account-name/
For example, if your account is masters, then your tree name is

/home/yformusers/masters

To clear the datafile once you have downloaded the data, you need to sign onto the institutional web server (www.usna.edu) and perform the following commands:

cd /home/yformusers/account-name/
cp /dev/null filename
For example, if your account is masters, then your tree name is

cd /home/yformusers/masters
cp /dev/null/database.txt


Sample Code

<html>

<head>

 

<title>Test Request Form</title>

</head>

 

<body bgcolor="#FFFFFF" text="#000080">

<center>
<font size=4>Test Request Form</font>
</center>

<font size=3>
 
<FORM METHOD="POST" ACTION="http://www.usna.edu/cgi-bin/yform">
<INPUT TYPE="HIDDEN" NAME="sort" VALUE="order:name,department,email,phone">
<INPUT TYPE="HIDDEN" NAME="print_blank_fields" VALUE="1">
<INPUT TYPE="HIDDEN" NAME="recipient" VALUE="webmaster@usna.edu">
<INPUT TYPE="HIDDEN" NAME="return_link_url" VALUE="http://www.usna.edu/Masters/questions/quest-012.htm">
<INPUT TYPE="HIDDEN" NAME="return_link_title" VALUE="Masters FAQ">
<INPUT TYPE="HIDDEN" NAME="database" VALUE="/home/yformusers/masters/database.txt">
<INPUT TYPE="HIDDEN" NAME="delimiter" VALUE=",">
<INPUT TYPE="HIDDEN" NAME="required" VALUE="name,department,email,phone">
<INPUT TYPE="HIDDEN" NAME="sendcourtesy" VALUE="yes">
<INPUT TYPE="HIDDEN" NAME="courtext1" VALUE="Thank you for filling out the sample Survey">
<INPUT TYPE="HIDDEN" NAME="courtclose" VALUE="USNA Webmaster">
<INPUT TYPE="HIDDEN" NAME="resptext1" VALUE="Thank you for your request.">

<PRE>
Name:           <input type="text" size="45" name="name">
Department:     <input type="text" size="35" name="department">
E-mail address: <INPUT TYPE="TEXT" SIZE="25" NAME="email"> (JohnPJones@nadn.navy.mil)
Phone number:   <input type="text" size="10" name="phone">

</PRE>
 
<P><BR><P>

<CENTER>
<INPUT TYPE=submit VALUE="Send Survey"> or
<INPUT TYPE=reset VALUE="Clear Survey">
</CENTER>
 
<br>
<br>
 
</body>
</html>


Code in Action

Test Request Form
Name:           
Department:     
E-mail address:  (JohnPJones@nadn.navy.mil)
Phone number:   


or


Contents of file /home/yformusers/masters/database.txt


2/28/2000,John Paul Jones,Leadership,JohnPJones@nadn.navy.mil,3-1111
2/28/2000,Oliver Hazard Perry,Pro Dev,Perry@nadn.navy.mil,3-2222
2/28/2000,Chester Nimitz,History,Nimitz@nadn.navy.mil,3-3333



United States Naval Academy