<!---
Name:        xforms1.cfm
Author:      Ben Forta (ben@forta.com)
Description: Flash form example
Created:     12/22/04
--->

<!--- Check that FilmID was provided --->
<!--- If yes, edit, else add --->
<cfset EditMode=IsDefined("URL.FilmID")>

<!--- If edit mode then get row to edit --->
<cfif EditMode>

 <!--- Get the film record --->
 <cfinvoke component="ows.14.movies"
           method="get"
           filmid="#URL.FilmID#"
           returnvariable="film">

 <!--- Save to variables --->
 <cfset MovieTitle=Trim(film.MovieTitle)>
 <cfset PitchText=Trim(film.PitchText)>
 <cfset AmountBudgeted=Int(film.AmountBudgeted)>
 <cfset RatingID=film.RatingID>
 <cfset Summary=Trim(film.Summary)>
 <cfset ImageName=Trim(film.ImageName)>
 <cfset DateInTheaters=DateFormat(film.DateInTheaters, "MM/DD/YYYY")>
 
 <!--- Form text --->
 <cfset FormTitle="Update a Movie">
 <cfset ButtonText="Update">
 
<cfelse>

 <!--- Save to variables --->
 <cfset MovieTitle="">
 <cfset PitchText="">
 <cfset AmountBudgeted="">
 <cfset RatingID="">
 <cfset Summary="">
 <cfset ImageName="">
 <cfset DateInTheaters="">

 <!--- Form text --->
 <cfset FormTitle="Add a Movie">
 <cfset ButtonText="Insert">

</cfif>

<!--- Get ratings --->
<cfinvoke component="ows.14.movies"
          method="getRatings"
          returnvariable="ratings">

<!--- Page header --->
<cfinclude template="../14/header.cfm">
 
<!--- Add/update movie form --->
<cfform format="flash"
        action="formdump.cfm">

<cfif EditMode>
 <!--- Embed primary key as a hidden field --->
 <cfinput type="hidden" name="FilmID" value="#Film.FilmID#">
</cfif>

   <cfinput type="Text"
            label="Movie:"
            name="MovieTitle"
            value="#MovieTitle#"
            message="MOVIE TITLE is required!"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="50"
            maxlength="100">
   <cfinput type="Text"
            label="Tag Line:"
            name="PitchText"
            value="#PitchText#"
            message="TAG LINE is required!"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="50"
            maxlength="100">
   <cfselect name="RatingID"
             label="Rating:"
             query="ratings"
             value="RatingID"
             display="Rating"
             selected="#VARIABLES.RatingID#" />
   <cftextarea label="Summary:"
               name="summary"
               cols="40"
               rows="5"
               wrap="virtual"><cfoutput>#Summary#</cfoutput></cftextarea>
   <cfinput type="Text"
            label="Budget:"
            name="AmountBudgeted"
            value="#AmountBudgeted#"
            message="BUDGET must be a valid numeric amount!"
            required="NO"
            validate="integer"
            validateAt="onSubmit,onServer"
            size="10"
            maxlength="10">
   <cfinput type="DateField"
            label="Release Date:"
            name="DateInTheaters"
            value="#DateInTheaters#"
            message="RELEASE DATE must be a valid date!"
            required="NO"
            validate="date"
            validateAt="onSubmit,onServer"
            size="10"
            maxlength="10">
   <cfinput type="Text"
            label="Image File:"
            name="ImageName"
            value="#ImageName#"
            required="NO"
            size="20"
            maxlength="50">
   <cfinput type="submit"
            name="BtnSubmit"
            value="#ButtonText#">
</cfform>

<!--- Page footer --->
<cfinclude template="../14/footer.cfm">
 