CiTi · Computer Coding · Year One · Unit 4
Student Handout
An admin is a set of private pages for changing a site’s data without opening the database file. Every table gets one folder with three pages:
[append].[replace].Three separate pages. The list has no form: it links to add.html, where the form lives. Each form uses action="[thisurl]" to send back to its own page. Every page is built in this order:
vars.inc includetitlevar, header.inc, nav.incfooter.incCode below is shown as a picture. Type it; pink ___ and <!-- your turn --> lines are yours to finish.
Make the folder. In amp, make 27admin27, and inside it state. Your admin lives at /citi/coding/2027/1/YOURINTS/amp/27admin27/state/.
Make index.html. Build it in the page order above. Inside the content div, add the link to add.html and this search. No form on this page. Fill in the blanks with the other fields.
[lookup] turns the country SKU into its name.lookinfield is the field to match in country.db, value is what to match it to, and returnfield is the field to print.Check it. Load the page. All 101 records should list, sorted by name, with country names, not numbers. An admin shows every record, active or not.
Make add.html. Same page order. Put this form in the content div and finish it.
f_ names keep form values apart from field tags like [TITLE].action tells the page the form was sent.[thisurl] is this page’s address, so the form sends back to itself.R_COUNTRY stores. Check state.db to see what that is.STATUS stores: 1 is active, 0 is not.Try it. Fill it in and submit. Nothing saves yet. That is Part C.
Add the processing block. Put this right after the vars.inc include, at the very top of add.html. Fill in the blanks.
| Piece | Job |
|---|---|
| [showif [action]=add] | Only runs when the form was sent. A plain visit skips it and shows the form. |
| [append db=...] | Adds one new line (record) to the end of the database. |
| autonumber=SKU | WebDNA fills in the SKU: the highest one so far, plus 1. |
| FIELD=value | One pair per field. The name must match the .hdr exactly. |
| & | Goes between pairs. This is how WebDNA knows where one value ends. |
| [url]...[/url] | Wraps anything a person typed, so an & in it cannot cut the value off. |
| [!] [/!] | Hides the line returns, so each pair can sit on its own line. |
| STATUS=[f_status] | From the status menu. Menu values are never typed, so no [url]. |
| [closedatabase] | Saves to the file now. The footer never runs, because... |
| [redirect index.html] | ...the browser is sent back to the list, which shows the new record. |
Add a state. Add Trinidad & Tobago, code TT, Active. It should appear on the list.
Check the file. Open state.db in CyberDuck. Find the new line and its SKU.
Check the contact form. Open your contact page. Your new state is in the menu, under its country.
Predict, change one thing, submit, check the list and state.db, then put it back. Delete test records in CyberDuck when you finish.
[url] and [/url] around [f_title]. Add Trinidad & Tobago again.& after the TITLE pair.TITLE= to TITEL=.&autonumber=SKU. Look at the new line in state.db.action input from the form.Add an Edit column. In index.html, add this cell as the last one in the row.
Hover each link: every URL carries that record’s SKU. The name is skuvar, never sku, so it cannot get mixed up with the [SKU] field.
Make edit.html. Same page order. Put this in the content div and finish it.
[input] puts each value in its box safely, even with quotes.selected goes on the option that matches the saved value.Why [statecountry]? Inside the country search, [SKU] means the country. Save the state’s country first, just like [countrysku] in the contact menu.
Check it. Click Edit on New York. Every box, the country, and the status should match the record.
Add the processing block. At the top of edit.html, after vars.inc. Fill in the blanks.
| [append] (add.html) | [replace] (edit.html) | |
|---|---|---|
| Does what | Adds a new record | Changes an existing record |
| Which record | A new one at the end | Every record that matches its search |
| SKU | autonumber=SKU makes one | eqSKUdatarq=[skuvar] finds one |
| STATUS | From the menu, Active first | From the menu, prefilled with selected |
Edit a state. Change Trinidad & Tobago’s status to Inactive and save.
Check it. The list shows 0, state.db shows 0, and it is gone from the contact menu.
Same routine: predict, change, test, check the file, put it back.
[input] and [/input] around [TITLE]. Edit a state named Trinidad & "Tobago".[showif] around selected on the country option. Edit New York.skuvar input, change a name, and save.[showif [action]=...]..hdr. A typo is dropped with no error.[url]. Put & between pairs.[replace] changes every record its search matches. Search by SKU.state.db, not just the page.