<!--- Is the form being submitted? --->
<CFSET WasFormSubmitted = IsDefined("FORM.RatingID")>

<!--- Insert film into database when form is submitted --->
<CFIF WasFormSubmitted>
  <!--- Insert film via Stored Procedure (via custom tag) --->
  <CF_spInsertFilm
    MovieTitle="#FORM.MovieTitle#"
    PitchText="#FORM.PitchText#"
    RatingID="#FORM.RatingID#"
    AmountBudgeted="#FORM.AmountBudgeted#"
    Summary="#FORM.Summary#"
    ReturnFilmID="InsertedFilmID"
    ReturnStatusCode="InsertStatus">
</CFIF>

<!--- Get list of ratings from database --->
<CFSTOREDPROC PROCEDURE="FetchRatingsList" DATASOURCE="owsServer">
  <CFPROCRESULT NAME="GetRatings">  
</CFSTOREDPROC>


<HTML>
<HEAD><TITLE>Film Entry Form</TITLE></HEAD>
<BODY>
<H2>Film Entry Form</H2>

<!--- Data entry form --->
<CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="POST" PRESERVEDATA="Yes">

  <!--- Text entry field for film title --->
  <P><B>Title for New Film:</B><BR>
  <CFINPUT NAME="MovieTitle" SIZE="50" MAXLENGTH="50"
    REQUIRED="Yes" MESSAGE="Please don't leave the film's title blank."><BR>

  <!--- Text entry field for pitch text --->
  <P><B>Short Description / One-Liner:</B><BR>
  <CFINPUT NAME="PitchText" SIZE="50" MAXLENGTH="100"
    REQUIRED="Yes" MESSAGE="Please don't leave the one-liner blank."><BR>
  
  <!--- Text entry field for expense description --->
  <P><B>New Film Budget:</B><BR>
  <CFINPUT NAME="AmountBudgeted" SIZE="15" 
    REQUIRED="Yes" MESSAGE="Please enter a valid number for the film's budget."
    VALIDATE="float"><BR>

  <!--- Drop-down list of ratings --->  
  <P><B>Rating:</B><BR>
  <CFSELECT
    NAME="RatingID"  
    QUERY="GetRatings"
    VALUE="RatingID"
    DISPLAY="Rating"/>

  <!--- Text areas for summary --->
  <P><B>Summary:</B><BR>
  <TEXTAREA NAME="Summary" COLS="40" ROWS="3" WRAP="soft"></TEXTAREA>  
    
  <!--- Submit button for form --->
  <P><INPUT TYPE="Submit" VALUE="Submit New Film">
</CFFORM>  



<!--- If we executed the stored procedure --->
<CFIF WasFormSubmitted>
  <!--- Display message based on status code reported by stored procedure --->
  <CFSWITCH EXPRESSION="#InsertStatus#">
    <!--- If the stored procedure returned a "success" status --->
    <CFCASE VALUE="1">
      <CFOUTPUT>
        <P>Film "#Form.MovieTitle#" was inserted as Film ID #InsertedFilmID#.<BR>
      </CFOUTPUT>  
    </CFCASE>
    <!--- If the status code was -1 --->
    <CFCASE VALUE="-1">
      <CFOUTPUT>
        <P>Film "#Form.MovieTitle#" already exists in the database.<BR>
      </CFOUTPUT>  
    </CFCASE>
    <!--- If the status code was -2 --->
    <CFCASE VALUE="-2">
      <P>An invalid rating was provided.<BR>
    </CFCASE>
    <!--- If any other status code was returned --->
    <CFDEFAULTCASE>
      <P>The procedure returned an unknown status code.<BR>
    </CFDEFAULTCASE>
  </CFSWITCH>
</CFIF>
  
  
</BODY>
</HTML>
