mojolicious template if statement

234 views
Skip to first unread message

Andrew Morgan

unread,
Mar 5, 2018, 10:51:23 PM3/5/18
to Mojolicious
Hello All,

I have the below code, but the if statement is not functioning.No matter what my selection is in the browser it returns "you entered correct car <name of the car>"

Please assist.Thank you 


use Mojolicious::Lite;


get '/' => sub {


my $self = shift;
$self
->render('index');
};


post
'/action' => sub{
my $c = shift;
$c
->render('response', msg => $c->param('cars'));
};


app
->start;


__DATA__


@@ index.html.ep


<!DOCTYPE html>
<html>
<body>


<form method= "POST" action="/action">
 
<select name="cars">
   
<option value="volvo">Volvo</option>
    <option value="saab">Saab</
option>
   
<option value="fiat">Fiat</option>
    <option value="audi">Audi</
option>
 
</select>
  <br><br>
  <input type="submit">
</
form>


</body>
</
html>


@@ response.html.ep


%if($msg == "fiat"){
You entered the correct car <%= $msg %>
%}else{
You did rubbish!! <%= $msg %>
%}

kitt

unread,
Mar 5, 2018, 10:59:41 PM3/5/18
to Mojolicious
Hi. Perl use 'eq' operator for string equal comparsion.
 Right syntax is:
%if($msg eq "fiat"){

вторник, 6 марта 2018 г., 13:51:23 UTC+10 пользователь Andrew Morgan написал:

Andrew Morgan

unread,
Mar 6, 2018, 5:34:44 PM3/6/18
to Mojolicious
Argh..lol, thank you very much..rookie mistake.

Thank you 
Reply all
Reply to author
Forward
0 new messages