• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to create an update form

New Here ,
Oct 27, 2009 Oct 27, 2009

Copy link to clipboard

Copied

I am facing some problems when creating an update form. I have created the form page and the action page. It seems to be working but I have a couple of issues with a list menu and a radio button.

The code is:

<!--- Check that ID was provided --->
<cfif NOT IsDefined("URL.ID")>
  <h1>You did not specify the Alumni ID</h1>
<cfabort>
</cfif>

<!--- Get the alumni record --->
<cfquery datasource="alumniupdateform" name="queryResults">
SELECT *
FROM Alumni
WHERE ID=#URL.ID#
</cfquery>

<!--- Get countries --->
<cfquery name="Countryquery" datasource="admissions">
      SELECT * FROM Countries ORDER BY CountryName ASC
</cfquery>

<!--- Page header --->
<cfinclude template="includes\header.cfm">

<!--- Update alumni form --->
<cfform action="includes\update_action.cfm">
<!--- Embed primary key as a hidden field --->


<cfoutput>
<input type="radio" name="WantRepresent" id="WantRepresent" value="#queryResults.WantRepresent#">
</cfoutput>

<cfoutput>
<input type="hidden" name="ID" value="#queryResults.ID#">
</cfoutput>
<table align="center" bgcolor="">
<tr>
  <th colspan="2">
    <p> </p>
    <p><font size="+1">Update a Alumni Contact</font></p>
    <p> </p></th>
</tr>
<tr>
  <td>
   Name:
  </td>
  <td>
   <cfinput type="Text"
            name="aName"
            value="#Trim(queryResults.aName)#"
            message="NAME is required!"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="50"
            maxlength="100">
  </td>
</tr>
<tr>
  <td>
   Last Name:
  </td>
  <td><cfinput type="Text"
            name="aLastName"
            value="#Trim(queryResults.aLastName)#"
            message="LAST NAME is required!"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="50"
            maxlength="100"></td>
</tr>
<tr>
  <td>
   Company:
  </td>
  <td>
   <cfinput type="Text"
            name="aCompany"
            value="#Trim(queryResults.aCompany)#"
            message="COMPANY is required!"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="50"
            maxlength="100">
            </td>
</tr>
<tr>
   <td>E-Mail</td>
   <td><cfinput type="Text"
            name="aEmail"
            value="#Trim(queryResults.aEmail)#"
            message="E-MAIL is required!"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="50"
            maxlength="100"></td>
</tr>
<tr>
  <td>
   Preferred Postal Adress::
  </td>
  <td>
   <cfoutput></cfoutput>
   <cfinput type="text"
   name="aPreferredAdress"
   value="#Trim(queryResults.aPreferredAdress)#"
   message="Please provide the company name"
   required="yes"
   validateAt="onSubmit,onServer"
   size="80"
   maxlength="100">
  </td>
</tr>
<tr>
  <td>
   Home Phone:
  </td>
  <td>
   <cfinput type="Text"
            name="aHomePhone"
            value="#Trim(queryResults.aHomePhone)#"
            message="Home Phone is required"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="20"
            maxlength="20">
  </td>
</tr>
<tr>
  <td>
   Work Phone:
  </td>
  <td><cfinput type="Text"
            name="aWorkPhone"
            value="#Trim(queryResults.aWorkPhone)#"
            message="Work Phone is required"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="20"
            maxlength="20"></td>
</tr>
<tr>
  <td>
   Cell Phone:
  </td>
  <td><cfinput type="Text"
            name="aCellPhone"
            value="#Trim(queryResults.aCellPhone)#"
            message="Cell Phone is required"
            required="Yes"
            validateAt="onSubmit,onServer"
            size="20"
            maxlength="20"></td>
</tr>
<tr>
   <td>Country:</td>
   <td><!--- Country list --->
   <select name="acountries">
    <cfoutput query="Countryquery">
     <option value="#CountryName#"<cfif Countryquery.CountryName IS queryResults.aCountry>selected</cfif>>#CountryName#</option>
    </cfoutput>
   </select></td>
</tr>
<tr>
   <td colspan="2"></td>
   </tr>
<tr>
   <td colspan="2"> <strong>
       
        </strong>
        <cfinput type="radio" name="WantRepresent" id="WantRepresent" value="Yes">
        Yes, I want to be a class representative of
       
<strong>
  <cfinput type="text" name="aYear" id="aYear" style="visibility:hidden">
</strong></td>
   </tr>
<tr>
   <td colspan="2"> </td>
</tr>
<tr>
  <td colspan="2" align="center">
   <input type="submit" value="Update">
  </td>
   </tr>
</table>

</cfform>

<!--- Page footer --->
<cfinclude template="includes\footer.cfm">

and the action code is this:

<!--- Update movie --->
<cfquery datasource="alumniupdateform" name="queryResults">
SELECT *
FROM Alumni
</cfquery>

<cfquery datasource="alumniupdateform">
UPDATE Alumni
SET aName='#Trim(FORM.aName)#',
    aLastName='#Trim(FORM.aLastName)#',
    aCompany='#Trim(FORM.aCompany)#',
    aEmail=#FORM.aEmail#,
    aPreferredAdress='#Trim(FORM.aPreferredAdress)#',
    aHomePhone='#Trim(FORM.aHomePhone)#',
    aWorkPhone='#Trim(FORM.aWorkPhone)#',
    aCellPhone='#Trim(FORM.aCellPhone)#',
    aCountry='#(FORM.acountries)#'
WHERE Id="#queryResults.ID#"
</cfquery>

<!--- Page header --->
<cfinclude template="includes\header.cfm">

<!--- Feedback --->
<cfoutput>
<h1>Contact '#FORM.aName#' updated</h1>
</cfoutput>

<!--- Page footer --->
<cfinclude template="includes\footer.cfm">

If someone can help me with this I would really appreciate.

Thanks

TOPICS
Advanced techniques

Views

680

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 27, 2009 Oct 27, 2009

Copy link to clipboard

Copied

LATEST

I see this comment on your form page.

<!--- Embed primary key as a hidden field --->

But on your action page, you don't use it.  That's a problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation