How Random Babbling Becomes Corporate Policy (t3knomanser) wrote in component_help,
How Random Babbling Becomes Corporate Policy
t3knomanser
component_help

  • Music:

Basic Query Handling (Or the "Would You Like a Cookie? Component")

This is another one of those things I discovered while skimming the docs. I'm not sure how to use this practically, but I can think of a few possibilities, like letting a user select certain layout or color options on a form, and having your journal change in response to them, or just simple toys and games like those ever popular quiz-sites. Think of that people, making your quiz right inside of your LJ, you'll be the talk of the LiveJournal Community. Think about how many people will friend you after that!

Okay, enough promo- time to work.

We're going to make a component that decides wether or not the user would like a cookie.


$f->flatbox_header(); 
#or, if you haven't used the flatbox tutorial:
#print_comp_header("Cookie?");
"""<form action="$p.base_url" method="get">"""; #this makes our journal the action of the form
    #Lets first see if someone already submitted to here.
    if ($p.args{"cookie"} == "yes") {  #the page class contains a hash "args". This is a named list basically, we want the element named "cookie"
       """You did like my cookie! Want another?<br/>""";
    } elseif ($p.args{"cookie"} == "no") {
	"""No? Are you sure?<br/>""";
    } else { #If they have submitted this form yet...
	"""Would you like a cookie?<br/>"""
    }
"""<label for=".cookie">Yes</label><input type="radio" name=".cookie" value="yes"/><br/> #Note that the field on the form is named ".cookie", but the value used above was just "cookie". 
#This is a requirement of S2.
#When making your own forms, follow this rule.
<label for=".cookie">No</label><input type="radio" name=".cookie" value="no"/><br/> <input type="submit" value="Get your cookie."/> </form> """; $f->flatbox_footer(); #or: #print_comp_footer();
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 2 comments