Reputation: 1471
I have an HTML5 form that calls a Perl controller to upload files to the server. It works. The thing is that if no file is selected (if the form box is left blank), and the user clicks the button, he will get a nasty Perl error message ("require file at ... line 39 etc"). I want to add a feature that if the form is left in blank, a message will appear saying "It's empty!". Can this be done only with HTML5, in the view? Or I need to modify my Perl script?
My HTMl5 looks like:
<form action="[% uri_for('/upload/execution') %]" method="post" enctype="multipart/form-data" class="form-horizontal">
<filedset>
<div class="control-group">
<p>
<div class="controls">
<input readonly value="[% article.article_id %]" name="article_id" type="hidden" class="span1" id="game_id">
</div>
</p>
<p>
<div class="form-actions">
<input type="submit" value="upload" class="btn btn-primary">
</div>
</p>
</filedset>
</form>
Upvotes: 0
Views: 301
Reputation: 858
You can use javascript to validate your request.
See this question, there is a good code sample.
Of course this is only client side validation (ie. it's done in browser), so anyone can turn it off and send the file anyway (although this rarely happens). It would be a good practice to handle this also on a script level.
Upvotes: 2