Yon Monk,
Your question has me a bit confused.

Exactly what does that mean? IMHO allowing the end user to drive an application to that level is a Bad Idea™.

If I am reading between the lines correctly you are writing an application that is a quiz of some sort. Am I close?

Here's my approach for that type of an application:

First I'd create a table in a database (fill in your favorite database here) that had the questions. Such as:

create table quiz_questions ( quiz_question_id serial not null primary key, question TEXT );
Depending on if I'm asking multiple choice questions or ask straight questions witn only once answer (much harder to automate the scoring of) I'm going to create a related table with valid answers. For the sake of this discussion I will use multiple choice in my implementation. Here is the related table:
create table quiz_answer( quiz_ansswer_id SERIAL not null primary key, quiz_question_id integer not null references quiz_question(quiz_question_id) on delete cascade, quiz_answer text not null, correct_answer boolean not null default 'false' );

To create the form here is a sniglet of code ( fetching things from the database is up to you to figure out).

| | Handwaving here | use strict; use CGI qw/ :all /; my $cgi = new CGI; # This hash reference contains the parameters for # the question... my $question = fetchRandomQueston(); # # This array contains hash references for the answers my @answers = fetchAnswers($question->{quis_question_id}); | | some handwaving here | print $question->{quiz_question},"\n"; print hidden("quiz_question_id", $queston->{quiz_question_id}),br; # There are better ways.. but I'm doing this way # for clarity my %labels = map { $_ -> {quiz_answer_id} => $_ ->{quiz_answer} } @answers; print radio_group( -name=> 'user_answer_rq', -values=> [ map { $_->{quiz_answer_id} } @answers ], -labels => \%labels, -linebreaks => 'true' ),br; print submit;

I've left a few details out, but you should be able to fill in the blanks by reading the man page for CGI.

Now once the person in question has selected an answer you can process it fairly easily as follows:

use CGI; my $cgi = new CGI; my $answer_id = $cgi->param('user_answer_rq'); my $question_id = $cgi->param('quiz_question_id'); my $answer=find_answer_in_db($answer_id}; if ( $answer->{correct_answer} ){ | process accordingly } else { | ditto }

That oughta give you a good start...


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: Organizing Form Input by blue_cowdawg
in thread Organizing Form Input by Spidy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.