← All Lessons Student Walkthrough →

CiTi · Computer Coding · Year One · Unit 3

True or False: Making Pages Decide with showif & hideif

A lesson within “My First Website & Server-Side Management”

Program Computer Coding: Year 1
Unit 3: My First Website & Server-Side Management
Duration One class period (~55 min): logic lab, then the send.html guard
Grouping Individual build, pair testing
Project MySite Logic Lab + contact form

Essential Question

From the Year 1 curriculum map
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.

Curriculum Map Alignment

Verbatim from Yr 1 curriculum

Concept / Knowledge / Content: Web Tools

  • Compare and contrast client-side and server-side technologies
  • Use templates and snippets to demonstrate efficient and consistent web site development

Projects & Activities

  • Client Managed Business Web Project: Contact Forms

Skills / Tasks

Demonstrates understanding in:

Reusable Code Assets Code Type via Syntax Website Planning & Construction
Previews Unit 4: the Yr 1 map lists form validation and server-side processing under Unit 4, Form Usage: “Define form validation and describe how it is accomplished”; “Connect an HTML form to a server-side script for processing.”
Builds on: HTML Forms & Sending Mail (the contact form, its hidden c_send field, and send.html) and Text Variables ([text] and the var naming rule).

Program Connections

Skills & Portrait alignment

Program Skills: What I’m Building Toward

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

NYS Portrait of a Graduate

Critical Thinker Academically Prepared Reflective and Future Focused

Guaranteed & Viable Curriculum Framework

3 Dimensions for this lesson

Integrated Academic Knowledge

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.”

Employability Skills

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.

Technical Skills

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.

Learning Intention

“Unwrapped” from the standard

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.

Success Criteria

  • I can explain what a boolean is and store a yes/no answer in a variable.
  • I can write [showif] and [hideif] with the right syntax: variable, operator, value, no spaces, no quotes.
  • I can use =, !, >, <, and ^, and I can nest two tests to mean “and.”
  • I can pair a [showif] with its mirror [hideif] so no value falls through the gap.
  • I can tell an empty variable from one that was never sent, and check for each.
  • I can stop send.html from sending email when someone just loads the page.

Authenticity Continuum

Where this lesson sits today
Instruction & Skill Practice
Teacher-Designed Simulation
Realistic Industry Task
Authentic Audience / Client
Product, Service, Impact, Solution

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.

Materials & Prep

  • Students’ MySite with 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.
  • Sublime Text, CyberDuck, Chrome
  • Student Walkthrough (y1-u3-l7-so) with six short videos (about a minute each). Students can rewatch them at home.
  • Teacher prep: before class, open your own demo send.html directly in the address bar. It should say Oops and send nothing.

How It Works

The logic and the syntax

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.

[showif question]The content goes on the page when the question is true.
[hideif question]The mirror: the content is left out when the question is true.
The anatomy
[showif [loggedinvar]=yes]<p>Welcome back!</p>[/showif]

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.

OpMeansExampleTrue whenLive result
=equals[showif [loggedinvar]=yes]loggedinvar is yestrue
!is not equal to[showif [loggedinvar]!yes]loggedinvar is anything but yesfalse
>greater than (numbers)[showif [scorevar]>67]68 and uptrue
<less than (numbers)[showif [scorevar]<67]66 and downfalse
^contains (text)[showif [namevar]^Diaz]Diaz anywhere in namevartrue

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.

Part 1: Logic Lab

showif, hideif, operators

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.)

logic/index.html
[include file=/citi/coding/2027/1/YOURINTS/mysite/includes/vars.inc] [text]titlevar=Logic Lab[/text] [include file=[incvar]header.inc] [include file=[incvar]nav.inc] <div class="bodycopy"> <div class="col-right"> <h2>Logic Lab</h2> [!] The answers. Change these, save, refresh. [/!] [text]loggedinvar=yes[/text] [text]scorevar=82[/text] [text]namevar=Jordan Diaz[/text] [!] 1. showif and its mirror, hideif [/!] [showif [loggedinvar]=yes]<p>Welcome back!</p>[/showif] [hideif [loggedinvar]=yes]<p>Please log in.</p>[/hideif] [!] 2. Numbers [/!] [showif [scorevar]>67]<p>You passed.</p>[/showif] [hideif [scorevar]>67]<p>Keep practicing.</p>[/hideif] [!] 3. Contains [/!] [showif [namevar]^Diaz]<p>A Diaz is here.</p>[/showif] [!] 4. Two questions: nest them [/!] [showif [loggedinvar]=yes] [showif [scorevar]>67]<p>Logged in AND passed.</p>[/showif] [/showif] </div> </div> [include file=[incvar]footer.inc]

Mirror pairs

A [showif] and a [hideif] with the same question always show exactly one of the two. This replaces “else” until students learn [if].

Nest for “and”

One question per tag. Two questions = one [showif] inside another; the inside only runs when the outside is true.

The 67 edge

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.

Checking for empty

Two ways, below. Never use “not empty” ([showif [x]!]) to ask whether something was sent.

Two ways to check “empty”

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.

1. Start it empty

When nothing else can set the variable, set it to nothing first. Then = with no value is a real empty test.

[text]notevar=[/text] [showif [notevar]=]<p>No note yet.</p>[/showif]

2. Compare it to its own name

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).

[showif [c_name]=[raw][c_name][/raw]] <p>No name was sent.</p> [/showif]

Part 2: The Guard

Fixing send.html

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?

contact/index.html: already in the form, above the button
<input type="hidden" name="c_send" value="yes">

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.

contact/send.html (updated)
[include file=/citi/coding/2027/1/YOURINTS/mysite/includes/vars.inc] [text]titlevar=Message Sent[/text] [!] Only send when the form said so. A direct visit has no c_send. [/!] [showif [c_send]=yes] [sendmail to=[emailvar]&from=[fromvar]&subject=MySite Contact Form] New message from the MySite contact form. Name: [c_name] Email: [c_email] Phone: [c_phone] Type: [c_type] Comments: [c_comments] -- Sent [date format=%B %d, %Y] at [time format=%I:%M %p] from IP [ipaddress] [/sendmail] [/showif] [include file=[incvar]header.inc] [include file=[incvar]nav.inc] <div class="bodycopy"> <div class="col-left"> <img src="[imgvar]mail.jpg" alt="an envelope"> </div> <div class="col-right"> [showif [c_send]=yes] <h2>Thanks!</h2> <p>Your message was sent. I will get back to you soon.</p> <p><a href="[pathvar]">Back to the home page</a></p> [/showif] [hideif [c_send]=yes] <h2>Oops</h2> <p>This page only works from the contact form.</p> <p><a href="[pathvar]contact/">Go to the contact form</a></p> [/hideif] </div> </div> [include file=[incvar]footer.inc]

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.

The Tricky Parts

All tested on our server

1Spaces and quotes make the test silently false

[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.

2Two separate tests leave a gap

[showif [scorevar]>67] plus [showif [scorevar]<67] show nothing at exactly 67. Use the mirror [hideif] with the same question.

3& 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.”

4No [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).

5Never sent is not empty

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.

6The guard is not a lock

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.

7Watch out: blank answers still send

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.

Teacher Watch List

  • Missing closing tags. A [showif] with no [/showif] swallows the rest of the page. Have students indent nested tags and count openers and closers.
  • Only [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.
  • Old forms: anyone who built the contact form before c_send was added gets Oops on every real send. Check the hidden field first.
  • Spelling must match between name="c_send" and [c_send], and between value="yes" and =yes.
  • Test without filling inboxes: the direct visit (Oops) costs nothing. Students only need one real send to prove Thanks still works.

What Comes Next

Mention, don’t teach

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.

[if "[loggedinvar]"="yes"] [then]<p>Welcome back!</p>[/then] [else]<p>Please log in.</p>[/else] [/if]

Lesson Flow

One period, ~55 min
TimePhaseWhat happens
3 minHookOpen 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 minVideos 1–3Booleans; [showif]/[hideif]; operators, the 67 edge, nesting. Pause on the anatomy: variable, operator, value.
12 minLogic LabBuild logic/index.html (walkthrough Part B). Flip yes/no and the score; predict before every refresh.
8 minBreak ItPart C, at least experiments 1, 2, and 5: the 67 gap, spaces around =, [else] inside [showif].
5 minVideos 4–5The page-load problem; the hidden field guard.
13 minThe GuardConfirm c_send is in the form, wrap [sendmail], add the Thanks/Oops mirror (Part D). Test a direct visit, then one real send.
7 minExit TicketWalkthrough 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.

Assessment

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.