CiTi · Computer Coding · Year One · Unit 3
Student Walkthrough
Your MySite contact page is going to work for real. A visitor fills in your form, clicks Send, and a few seconds later the message shows up in your email inbox.
send.html.send.html emails the answers to you with [sendmail].Day 1 you build and style the form. Day 2 you make it send.
These are the fields your form will have. Fields marked required must be filled in before the form can be sent.
| Label | Type of box | name | Required? |
|---|---|---|---|
| Name | Text box | c_name | Yes |
| Email box | c_email | Yes | |
| Phone | Phone box | c_phone | No |
| Type of contact | Drop-down list | c_type | Yes |
| Comments | Big text box | c_comments | Yes |
| (none: visitors never see it) | Hidden field, value yes | c_send | Always sent |
The c_ at the start of each name stands for “contact.” It makes the form’s names easy to spot in your code.
Open your contact page. In CyberDuck, go to mysite/contact/ and open index.html with Edit with Sublime Text. The top should already look like this from the last lesson:
Paste the form into your right column. Put it inside <div class="col-right">, replacing whatever is there now.
Read what you pasted. Find each of these in your code:
<fieldset> draws a box around a group of fields. <legend> is the group’s title. Your form has two groups: About You and Your Message.<label> has a for that matches its box’s id. That connects them.name is the name the server sees. A box with no name is never sent.required means the browser won’t send the form while that box is empty.value="" (empty). That’s what lets required work on a drop-down.type="hidden" is a box nobody sees. It always sends c_send=yes with the form. That is how send.html will know a message really came from your form. You put it to work in the next lesson.Save and test in your browser. Open your contact page on your live site. Click a label: the cursor should jump into its box. Click Send Message with everything empty: the browser should stop you and point at the first required box. (Sending does not work yet. That’s Day 2.)
Add the form CSS. Open css/style.css and paste this at the very bottom. Read the comments: they tell you what each line does.
Make it yours. Change the greens to colors that match your site. Then test with the keyboard only: press Tab to move through every box and the button. The box you are in should turn green (or your color).
font-family: inherit; fix? (Hint: try deleting it.)
Your teacher will give you the From address. Write both addresses here first:
Add two settings to vars.inc. Open includes/vars.inc and add these lines at the bottom, using your two addresses. No spaces around the =.
Make the send page. In CyberDuck, inside mysite/contact/, make a New File named send.html and open it with Sublime. Paste this whole thing in. Change YOURINTS on the first line, and change mail.jpg to one of your own images.
Read what send.html does:
[sendmail] line has three settings: to (where the email goes), from, and subject. They are joined with &.[sendmail] and [/sendmail] is the text of the email.name in brackets. name="c_comments" becomes [c_comments].This page sends an email every time it loads. It does not check anything yet. In a follow-up lesson you will teach it to check the answers first.
Connect the form to the send page. Your form tag already says action="[pathvar]contact/send.html" and method="post". Check that they are there.
Send yourself a test. Fill in your whole form on your live site and click Send Message. You should see your Thanks page. Check your inbox (and your spam folder). The email should look like this:
Don’t refresh the Thanks page. The browser will offer to send the form again, and if you say yes, you get a second email.
Real developers test what happens when things go wrong, not just when they go right.
One change at a time. Predict first, test, then undo it before the next one.
required from the Name box, then send the form with Name emptymethod="get", send it, and look at the address barname="c_comments" from the textarea, then send a complete formfor to for="nme", then click the word Namefor must match the box’s id exactly.name, and the names must match send.html.required and a red star, and say what the star means.send.html without your form. Next lesson, you will make it check the answers.[sendmail] only goes in send.html. It runs every time its page loads.[sendmail] tag’s settings.Check each one when you feel confident you can do it.
Use this space for anything: questions, reminders, code you want to keep.