I have a task in the Mojolicious framework, not the Lite version. I create HTML form in the templates folder, when the user submitted the data from this folder will be saved in another HTML file in templates, and also when you click the submit results it will route you to this file, in this file, there will be your data and to buttons -> go back and you will route to your form with the same results, or the save button, and this will route you to the new clear form.
I must use only routes, template folder, and controller, without javascript, referrer and etc.
As I understand I must use the if statements in the controller? or what to write in the HTML file that will save the results of user and routing back or to save?
My form in template folder:
<form action="/results" method="POST">
<label for="fname">Your name:</label><br>
<input type="text" id="fname" name="fname" value="<%= $guestname; %> " > <br>
<label for="lname">Your Sirname:</label><br>
<input type="text" id="lname" name="lname" value= " <%= $guestsirname %> " ><br>
<label for="username">Login</label><br>
<input name="username" type="text" value=" <%= $admin; %>"><br>
<label for="password">Password</label><br>
<input name="password" type="password" value=" <%= $passwordin; %> ">
<p><input type="submit" value="Отправить"
<%= $loging; %>
</form>
My controller:
sub formguest($self) {
my $username = $self->param('username');
my $password = $self->param('password');
my $nameguest = $self->param('nameguest');
my $sirnameguest = $self->param('sirnameguest');
$self->render(template =>'forma/userform',
admin=>"$username",
passwordin=> "$password",
loging => 'Thanks!',
guestname => "$nameguest",
guestsirname => "$sirnameguest"
);
}
My route:
$r->get('/forma')->to('example#formguest');
$r->post('/forma')->to('example#formguest');