package App;use Dancer2;use Data::Dumper;get '/' => sub {return <<'HTML';<form action="/q-1" method="GET"><p>Did you ever drink coffee?</p><input type="text" name="coffee"><p>What is your age?</p><input type="text" name="age"><input type="submit"></form>HTML};get '/q-1' => sub {my %FIELD;my @field_names = qw(coffee age);foreach my $field_name (@field_names) {if ( defined param("$field_name") ) {$FIELD{$field_name} = param("$field_name");}}print Dumper \%FIELD;if ( $FIELD{'coffee'} eq "yes" && $FIELD{'age'} >= 16 ) {# redirect '/more-questions';redirect '/bike';}else {redirect '/other-questions';}if ( $FIELD{'age'} > 16 ) {redirect '/bike';}};get '/more-questions' => sub {return "More questions";};get '/other-questions' => sub {return "Other questions";};get '/bike' => sub {return "In my country you may ride a scooter though it is better to bike!";};App->to_app;
On 16 Feb 2021, at 00:26, Richard Reina <gatorreina@gmail.com> wrote:I have a friend who needs me to develop a page which is a long survey, There is some skip logic needed, for example, if users birthday is before x date skip to question 5, if answer to question 12 is 'no' skip to question 16, but nothing too complicated. I nevertheless am struggling with how to design such a route and was wondering if anyone perhaps knew of any similar examples._______________________________________________Rciahrd
dancer-users mailing list
dancer-users@lists.preshweb.co.uk
https://lists.preshweb.co.uk/mailman/listinfo/dancer-users