Web Rule Exercises
Objective
Introduce actions and techniques for using KRL on the Web.
Preparation
- Read Chapter 7 of The Live Web.
- Create and register (using KDK) a new ruleset to use for the following exercises.
Exercises
- Write a rule called
show_form
that inserts text paragraph (make up the text) in the<div/>
element with the ID of main onktest.heroku.com
. - Modify the
show_form
rule from (1) to place a simple Web form that has fields for a first name, a last name, and a submit button. Use thewatch()
action to watch it for activity. - Write a rule that selects on submit and takes the first and last name from the form in (3) and stores them in entity variables.
- Modify the ruleset so that if a first and last name have been stored, they are displayed in the page (in a paragraph under the form) and if they are not, the form is displayed.
- Add a clear rule that clears the names if the query string
clear=1
is added to the URL.
Copyright Picolabs | Licensed under Creative Commons.