I do have HTML inside CGI code as following
app->start
__DATA__
@@ rout.html.ep
<% if ($errormsgs) { %>
<% for my $e (@$errormsgs){ %>
<%=$e%>
<br>
<% } %>
<a href="<%= url_for('/') %>">Go back to fix the form</a><br>
<% } %>
<% else{ %>
<%=$successmsg %>
<a href="<%= url_for('/') %>">Send another?</a><br>
<% } %>
and my CGI code is:
if (sendmail %mail) {
$ok .= "Congratulation, your mail was sent!";
$self->stash ( successmsg => $ok );
}
else {
push @errors, "Error sending: $Mail::Sendmail::error";
}
}
$self->stash ( errormsgs => \@errors );
$self->render ( 'rout' );
@errors
work perfectly fine, but successmsg
I get:
syntax error at template rout.html.ep from DATA section line 8, near ";
else"
Global symbol "$successmsg" requires explicit package name at template rout.html.ep from DATA section line 9.
syntax error at template rout.html.ep from DATA section line 11, near "} $_M "
syntax error at template rout.html.ep from DATA section line 11, near "} }"
6
<a href="<%= url_for('/') %>">Go back to fix the form</a><br>
7
<% } %>
8
<% else{ %>
9
<%=$successmsg %>
10
<a href="<%= url_for('/') %>">Send another?</a><br>
11
<% } %>
and I don't know what I did wrong, so any ideas?
The previous method didn't work so I ended up declaring an array and pushed the message into it and now it works.
CGI Code:
my @success;
push @success, "Congratulation, your mail was sent!";
$self->stash ( successmsg => \@success);
HTML Code:
<% if ($successmsg) { %>
<% for my $s (@$successmsg) { %>
<%=$s %>
<% } %>
<% } %>
Hope that helps in the future