Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In my data entry form page, I now have two conditional logic sections. One for when the form is submitted, and one for when the page is loaded with the url.photographerid variable. The next job is to fill in form controls, so that they show either new values for an insert form or existing values for an update form. To accomplish this, I'll go to the second conditional block, the one where I've retrieved the photographer object, and I'll take each of those values and pass them to the form scope, like this.
I'll start with the firstname variable. I'll set a variable named form. firstname and I'll get its value from the method photographer.getFirstName. I'll clone that line of code 3 times, 1, 2, 3. And I'll set each of the form variables to match the name of the column. Here is the value for the lastname and I'll match the method name. I'll do the same thing for the featured column, setting a variable called form.featured and for the photographerid value I'll set a variable called form.photographerid.
That's the primary key and I'll set the value of this one from url.photographerid. So now, the form scope contains all of the values for the existing data. I am also going to add three more cfparam tags up at the top of the page. These param tags will be used to set default values if the page is loaded without the URL variable. I'll clone that line of code, holding down Ctrl+Alt on Windows or Command+Alt on Mac and pressing the Down Arrow and once again, I'll clone it three times.
For all three variables, form.firstname, form.lastname and form.photographerid, I'll set the default values to blank strings. So now the logic is if the page is loaded from scratch, the default values of the form variables will be zero for featured and blank strings for the others, but if it's loaded with the URL variable as a result of a click on an edit link, then these form variables will contain the values from the orm object. Finally, I'll fill in the values.
I'll go to each of the cfinput tags. For the text controls, firstname and lastname, I'll set a variable called value, and I'll set the value from the form variable form.firstname for the first one, and form.lastname for the second one. The checkbox control will be handled differently. The value is always set to 1. Instead you use a checked attribute to indicate whether you want the control to be checked or not.
I'll put in checked= and then a value of form.featured. This variable will have a value of 0 or 1. If the value is 0 that will equate to false, meaning the input control will not be checked. And if it's 1, it will equate to true. Finally, I need to track the primary key of the selected record, photographerid. For this, I'll use a hidden control. I'll add another cfinput tag, this one with a type of hidden.
I'll give it a name matching the primary key column name, photographerid, and I'll give it a value of form.photographerid. So now, all four of my columns are being tracked in the form. The three that are visible to the user are the firstName and lastName as text controls and the featured value as a check box. The photographerid, which is the primary key, is hidden from the user. If I load the page without passing in a photographerid URL variable, I see the default values that I created with cfparam tags at the top of the code.
One last step, I'll remove my temporary debugging code that was outputting the value of the current photographer. I'll save the change to that file and I'll reopen the index.cfm file from the Photographers folder. I'll run that and I'll click one of the edit links and I'll see the data from the selected photographer. Now this time, I'll run the page in an external browser. I'll click a link for a photographer and I see their data.
I'll go back a step, I'll click a link for another photographer and I'll see their data, and notice that the firstName, lastName and featured controls are being correctly filled in. And finally, I'll click the Insert Photographer link and that'll take me to the exact same form but with the default values displayed. I am now ready for the last bit of code in this form system, which is to provide code to update an existing photographer record.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101348 Viewers
61 Video lessons · 88108 Viewers
71 Video lessons · 71952 Viewers
56 Video lessons · 103776 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.