CiTi · Computer Coding · Year One · Unit 3
A lesson within “My First Website & Server-Side Management”
What are databases? What should be stored in DBs vs. files?
A data-driven page has to decide what to show: this record or that one, a thanks message or an error, a form that sends or one that refuses. Every one of those decisions is a true-or-false question. This lesson teaches students to ask those questions on the server with [showif] and [hideif], and uses them to fix the open problem from the contact form lesson: send.html sends an email every time it loads.
Demonstrates understanding in:
Reusable Code Assets Code Type via Syntax Website Planning & Constructionc_send field, and send.html) and Text Variables ([text] and the var naming rule).Hands-On:
#6 Work a problem through Define→Prepare→Try→Reflect
#7 Validate and debug my own work
Professional:
#7 Treat a mistake as data, not failure
#9 Document as you go
Logic and inequalities: a statement is true or false; “greater than 67” and “less than 67” both leave out 67 itself, so the opposite of > is ≤, not <. Reading conditions precisely, the way a math proof reads “and” and “not.”
Testing edge cases on purpose (the value right on the boundary, the page opened directly, the variable that never arrived). Writing a short comment that says why a check exists, so the next developer doesn’t delete it.
Storing a yes/no answer in a [text] variable; writing [showif] and [hideif] with the =, !, >, <, and ^ operators; pairing a test with its mirror so every value lands in one branch; nesting for “and”; checking for empty and never-sent variables; and guarding [sendmail] with the form’s hidden c_send field.
Students will understand that a server-side page can ask true-or-false questions and send different HTML depending on the answer: and will use [showif] and [hideif] to make send.html send email only when it was reached from their contact form.
[showif] and [hideif] with the right syntax: variable, operator, value, no spaces, no quotes.=, !, >, <, and ^, and I can nest two tests to mean “and.”[showif] with its mirror [hideif] so no value falls through the gap.send.html from sending email when someone just loads the page.The first half is skill practice in a Logic Lab page. The second half fixes a real defect in a live feature (a contact form that emails on every page load), the same kind of bug report a working developer gets. Push further: pairs try to make each other’s send.html send without using the form, then write up what they found.
vars.inc, the three includes, and the working contact form and send.html from the previous lesson. The form must have the hidden c_send field; add it now for anyone who built the form before it was in the lesson.send.html directly in the address bar. It should say Oops and send nothing.A boolean is a question with exactly two answers: true or false. WebDNA has no true/false type, so the answer lives in a [text] variable as yes/no (databases use 1/0 in a status field). Name it for the question and end it in var: loggedinvar, sentvar.
The question is three parts written together: the variable in brackets ([loggedinvar]), an operator (=), and a value (yes). No spaces and no quotes: either one makes the test silently false (tested).
Content in a false branch is not hidden with CSS. It is never processed and never sent. A [text] inside a false [showif] does not run (tested), which is why a [sendmail] inside one cannot fire.
Live column: this lesson page sets loggedinvar=yes, scorevar=82, namevar=Jordan Diaz, and the server fills in the last column every time the page loads.
| Op | Means | Example | True when | Live result |
|---|---|---|---|---|
| = | equals | [showif [loggedinvar]=yes] | loggedinvar is yes | true |
| ! | is not equal to | [showif [loggedinvar]!yes] | loggedinvar is anything but yes | false |
| > | greater than (numbers) | [showif [scorevar]>67] | 68 and up | true |
| < | less than (numbers) | [showif [scorevar]<67] | 66 and down | false |
| ^ | contains (text) | [showif [namevar]^Diaz] | Diaz anywhere in namevar | true |
Text comparisons ignore capital letters (YES matches yes). > and < compare as numbers (100>82 is true, 9>82 is false). There is a sixth operator, ~; it is not part of this lesson.
Students make a new practice page, mysite/logic/index.html. They set the answers by hand at the top, then change them, save, and refresh to watch the page decide. (The lab page doesn’t go in the nav.)
A [showif] and a [hideif] with the same question always show exactly one of the two. This replaces “else” until students learn [if].
One question per tag. Two questions = one [showif] inside another; the inside only runs when the outside is true.
Lab step: replace the [hideif] with [showif [scorevar]<67] and set the score to 67. Neither message shows (nothing / nothing on this page right now). The mirror fixes it: Keep practicing.
Two ways, below. Never use “not empty” ([showif [x]!]) to ask whether something was sent.
A variable that was never set prints its own name in brackets, so it is not empty. Live on this page, for a variable that was never set: “not empty” [showif [neversentvar]!] is true, and “empty” [showif [neversentvar]=] is false.
When nothing else can set the variable, set it to nothing first. Then = with no value is a real empty test.
When a blank [text] would wipe out a form variable with the same name, check whether it was ever declared. It matches its [raw] self only when it was never sent (live: true).
The cliffhanger from the contact form lesson: [sendmail] runs every time send.html loads, so typing its address (or a search-engine bot finding it) sends an email full of bracketed names. The fix is one yes/no question: did this visit come from my form?
The visitor never sees it, but every submit sends c_send=yes. A direct visit sends nothing, so [c_send] prints as its own name and [c_send]=yes is false.
Two changes: the whole [sendmail] is wrapped in [showif [c_send]=yes], and the message is a mirror pair, Thanks or Oops. Tested on the teacher demo: a direct visit shows Oops and sends nothing.
[showif [x] = yes], [showif [x]= yes], and [showif [x]="yes"] are all false even when x is yes. No error appears; the content just never shows.
[showif [scorevar]>67] plus [showif [scorevar]<67] show nothing at exactly 67. Use the mirror [hideif] with the same question.
& is not “and”[showif [a]=yes&[b]>99] still showed its content when the second part was false. One question per tag; nest for “and.”
[else] inside [showif][showif ...]A[else]B[/showif] stops the page with “An unknown error occurred: IfNotFound” and everything after it is lost. Use a mirror pair now; [else] belongs to [if] (next lesson).
A variable that never arrived prints its own name, so “not empty” ([showif [c_name]!]) is true on a direct visit. Ask for an exact value (=yes), start variables empty, or compare to the [raw] name.
Variables also come from the address bar: send.html?c_send=yes passes the check (tested). The hidden field stops page loads, refreshes from a link, and crawlers. It does not stop a person who reads the form’s source.
The guard only asks where the visit came from, not whether the answers are any good. Someone can delete required in the browser’s inspector, or type only spaces, and the form still sends. Checking each field on the server is coming; for now, students should know the gap exists.
[showif] with no [/showif] swallows the rest of the page. Have students indent nested tags and count openers and closers.[sendmail] goes inside the guard, not the includes. If the header include ends up inside it, a direct visit shows a page with no header.c_send was added gets Oops on every real send. Check the hidden field first.name="c_send" and [c_send], and between value="yes" and =yes.A follow-up lesson introduces [if], which holds both answers in one tag. Its rules differ: text must be in quotes, and an unquoted test quietly goes to the else branch with no error.
| Time | Phase | What happens |
|---|---|---|
| 3 min | Hook | Open a student’s unguarded send.html in the address bar (with permission) and read the bracketed email aloud. “By the end of class, this page will refuse.” |
| 7 min | Videos 1–3 | Booleans; [showif]/[hideif]; operators, the 67 edge, nesting. Pause on the anatomy: variable, operator, value. |
| 12 min | Logic Lab | Build logic/index.html (walkthrough Part B). Flip yes/no and the score; predict before every refresh. |
| 8 min | Break It | Part C, at least experiments 1, 2, and 5: the 67 gap, spaces around =, [else] inside [showif]. |
| 5 min | Videos 4–5 | The page-load problem; the hidden field guard. |
| 13 min | The Guard | Confirm c_send is in the form, wrap [sendmail], add the Thanks/Oops mirror (Part D). Test a direct visit, then one real send. |
| 7 min | Exit Ticket | Walkthrough exit ticket. Mention the blank-answer gap and [if] as what comes next. Video 6 and Part E (empty checks) for anyone who finishes early, or at home. |
Formative: Live check of logic/index.html (four sections work and flip correctly, 67 shows Keep practicing) and send.html (direct visit shows Oops and sends nothing; a real form shows Thanks and delivers the email).
Exit ticket (completion-graded): “Your score test is [showif [scorevar]>67]. Write the tag that shows Keep practicing for every other score, and explain why [showif [scorevar]<67] is wrong. Then explain why [showif [c_send]!] would not protect send.html.”
Extension: On the Thanks branch, show an extra line only when c_type is Bug Report. Then use the [raw] check to show “No name was sent” inside the Oops branch.