Created
May 19, 2014 07:58
-
-
Save memememomo/1aba2ab0f5e22d7599ce to your computer and use it in GitHub Desktop.
Mojoliciousでfillinformする ref: http://qiita.com/uchiko/items/89f95a48fc28c049ac4a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cpanm Mojolicious::Plugin::FillInFormLite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
plugin 'FillInFormLite'; | |
get '/user/update' => sub { | |
my $self = shift; | |
my %filled = ( | |
name => '太郎', | |
gender => 'male', | |
birthday_year => 1983, | |
birthday_mon => 12, | |
birthday_day => 27, | |
lang => ['perl','php','ruby'], | |
note => "ほげほげほげほげ\nほげほげほげ", | |
); | |
$self->render_fillinform(\%filled, mons => [1..12], days => [1..31]); | |
} => 'user/update'; | |
app->start; | |
__DATA__ | |
@@ user/update.html.ep | |
<html> | |
<head> | |
<meta charset="utf8"> | |
<title>ユーザー情報</title> | |
</head> | |
<body> | |
<h1>ユーザー情報</h1> | |
<form action="<%= url_for %>" method="post"> | |
<table> | |
<tr> | |
<td>お名前</td> | |
<td><input type="text" name="name"></td> | |
</tr> | |
<tr> | |
<td>性別</td> | |
<td> | |
<input type="radio" name="gender" value="male">男 | |
<input type="radio" name="gender" value="famale">女 | |
</td> | |
</tr> | |
<tr> | |
<td>誕生日</td> | |
<td> | |
<input type="text" name="birthday_year">年 | |
<select name="birthday_mon"> | |
<% for my $mon (@$mons) { %> | |
<option name="birthday_mon"><%= $mon %></option> | |
<% } %> | |
</select>月 | |
<select name="birthday_day"> | |
<% for my $day (@$days) { %> | |
<option name="birthday_day"><%= $day %></option> | |
<% } %> | |
</select>日 | |
</td> | |
</tr> | |
<tr> | |
<td>使用言語</td> | |
<td> | |
<input type="checkbox" name="lang" value="perl">Perl | |
<input type="checkbox" name="lang" value="php">PHP | |
<input type="checkbox" name="lang" value="ruby">Ruby | |
<input type="checkbox" name="lang" value="python">Python | |
<input type="checkbox" name="lang" value="go">Go | |
</td> | |
</tr> | |
<tr> | |
<td>備考</td> | |
<td><textarea name="note" rows="10"></textarea></td> | |
</tr> | |
</table> | |
<input type="submit" value="更新"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment