english

learn php

learn css

learn html

learn javascript

learn php

9. web

assignments
7 minutes / 1309 words

nine / assignments

while, in the real world, i suggest completely avoiding the use of html form submissions, we haven't gotten to their more modern replacements so we'll use basic forms to provide data to our php programs for the moment...

assignments before this were all functional either on web servers or using the command-line. this is where that ends and you have to use a web server if you haven't been so far.

the html code will be provided but you can change it if you like. you're only responsible for creating the php side of the equation.

assignment 9.1

this is an extension of assignment 8.1.

write a program that takes the input from this form and returns a list of validly-formatted emails.

<form method="post" action="parse.php">
    <textarea name="source" placeholder="paste text containing emails here"></textarea>
    <input type="submit" value="go" />
</form>

the program should be able to take the html source of a page or delimited table and turn it into a list of emails. ensure they are all lowercase, in alphabetical order and without duplicates.

test it with the contact page of any business or college faculty with a long list of emails. you can also use the output of assignment 8.2 to check its ability to strip emails from unformatted text.

assignment 9.2

write a program that takes the input from this form and checks to ensure the user has submitted valid information.

<form method="post" action="signup.php">
    <input type="text" name="name" placeholder="jane doe" />
    <input type="text" name="email" placeholder="[email protected]" />
    <input type="password" name="password" placeholder="password" />
    <input type="password" name="passwordVerify" placeholder="verify password" />
    <label for="agree">i agree to the terms and conditions.</label><input type="checkbox" name="agree" id="agree" value="yes" />
    <input type="submit" value="go" />
</form>
  • name should be at least two words containing valid letters and only the special characters possible for names (accented letters and non-latin alphabets/syllabaries, apostrophes, hyphens, spaces).
  • email should be a validly-formatted email.
  • password should match and contain at least one letter, one number and one symbol and be a minimum of eight characters long.
  • user must have agreed to the terms and conditions.

if the user has successfully submitted all that information correctly, welcome them and generate a hashed version of the password then create a unique id for the user and a verification link to be emailed to them and build an email.

if they haven't, display an error specifying which conditions were not met.

assignment 9.3

this is an extension of assignment 8.2.

create a program that allows the user to add a new contact to your existing address book, verifies and processes the new information then displays the entire address book using this form.

<form method="post" action="add.php">
    <label for="name">name</label>
    <input type="text" id="name" name="name" placeholder="jane doe" /><br />
    <label for="nickname1">nickname (1)</label>
    <input type="text" id="nickname1" name="nickname1" placeholder="smol" /><br />
    <label for="nickname2">nickname (2)</label>
    <input type="text" id="nickname2" name="nickname2" placeholder="puppy" /><br />
    <label for="nickname3">nickname (3)</label>
    <input type="text" id="nickname3" name="nickname3" placeholder="girl" /><br />
    <label for="pronouns">pronouns</label>
    <input type="text" id="pronouns" name="pronouns" placeholder="they/them" /><br />
    <label for="birthdate">birthdate</label>
    <input type="date" name="birthdate" /><br />
    <label for="addressLabel1">address (1)</label>
    <input type="text" name="addressLabel1" placeholder="home" />
    <textarea name="address1" placeholder="10 first street&#10;vancouver, bc v6a 3q4"></textarea><br />
    <label for="addressLabel2">address (2)</label>
    <input type="text" name="addressLabel2" placeholder="work" />
    <textarea name="address2" placeholder="10 first street&#10;vancouver, bc v6a 3q4"></textarea><br />
    <label for="addressLabel3">address (3)</label>
    <input type="text" name="addressLabel3" placeholder="temporary" />
    <textarea name="address3" placeholder="10 first street&#10;vancouver, bc v6a 3q4"></textarea><br />
    <label for="emailLabel1">email (1)</label>
    <input type="text" id="emailLabel1" name="emailLabel1" placeholder="home" />
    <input type="text" id="email1" name="email1" placeholder="[email protected]" /><br />
    <label for="emailLabel2">email (2)</label>
    <input type="text" id="emailLabel2" name="emailLabel2" placeholder="work" />
    <input type="text" id="email2" name="email2" placeholder="[email protected]" /><br />
    <label for="emailLabel3">email (3)</label>
    <input type="text" id="emailLabel3" name="emailLabel3" placeholder="temporary" />
    <input type="text" id="email3" name="email3" placeholder="[email protected]" /><br />
    <label for="phoneLabel1">phone (1)</label>
    <input type="text" id="phoneLabel1" name="phoneLabel1" placeholder="home" />
    <input type="text" id="phone1" name="phone1" placeholder="+1 604 222 2222" /><br />
    <label for="phoneLabel2">phone (2)</label>
    <input type="text" id="phoneLabel2" name="phoneLabel2" placeholder="work" />
    <input type="text" id="phone2" name="phone2" placeholder="+1 604 222 2222" /><br />
    <label for="phoneLabel3">phone (3)</label>
    <input type="text" id="phoneLabel3" name="phoneLabel3" placeholder="temporary" />
    <input type="text" id="phone3" name="phone3" placeholder="+1 604 222 2222" /><br />
    <label for="urlLabel1">url (1)</label>
    <input type="text" id="urlLabel1" name="urlLabel1" placeholder="home" />
    <input type="text" id="url1" name="url1" placeholder="https://php.org" /><br />
    <label for="urlLabel2">url (2)</label>
    <input type="text" id="urlLabel2" name="urlLabel2" placeholder="work" />
    <input type="text" id="url2" name="url2" placeholder="https://php.org" /><br />
    <label for="urlLabel3">url (3)</label>
    <input type="text" id="urlLabel3" name="urlLabel3" placeholder="temporary" />
    <input type="text" id="url3" name="url3" placeholder="https://php.org" /><br />
    <label for="socialLabel1">social (1)</label>
    <input type="text" id="socialLabel1" name="socialLabel1" placeholder="instagram" />
    <input type="text" id="social1" name="social1" placeholder="jane123" /><br />
    <label for="socialLabel2">social (2)</label>
    <input type="text" id="socialLabel2" name="socialLabel2" placeholder="tiktok" />
    <input type="text" id="social2" name="social2" placeholder="jane123" /><br />
    <label for="socialLabel3">social (3)</label>
    <input type="text" id="socialLabel3" name="socialLabel3" placeholder="discord" />
    <input type="text" id="social3" name="social3" placeholder="jane123" /><br />
    <label for="notes">notes</label>
    <textarea name="notes" placeholder="woof?"></textarea><br />
    <input type="submit" value="add" />
</form>

if there's no name, show an error. yes, this is limited to a maximum of three for multiple-entry fields but there's no need to overcomplicate it.

you'll need to convert the date to unix time.

you can leave any missing fields (other than name) out instead of inserting them blank.

don't forget to update the created and last-updated fields.

assignment 9.4

this is an extension of assignment 8.2/8.3.

create a program that allows searching your address book from this form. if the search field is blank, show the whole address book.

<form method="get" action="search.php">
    <input type="text" name="search" placeholder="jane" />
    <input type="submit" value="search" />
</form>

learn php

learn css

learn html

learn javascript

powered by akelei. an avi sato project.