Skip to content

Commit

Permalink
Bug fixes to blank or broken form submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Taylor committed Jun 8, 2011
1 parent 0255bbd commit dddf773
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/Wardrobe/Controller/Root.pm
Expand Up @@ -70,6 +70,11 @@ sub csv_upload :Chained('root') :Args(0) {
my @results = ();
my $upload = $c->req->upload('csv_file');

if (!defined($upload)) {
$c->res->redirect($c->uri_for(''));
return;
}

# assume header record for website
my ($rows, $bad, $dupes) = Wardrobe::Model::Interface->create_from_csv_file($upload->tempname, 1);

Expand Down
12 changes: 9 additions & 3 deletions lib/Wardrobe/Controller/Tags.pm
Expand Up @@ -3,6 +3,7 @@ use Moose;
use namespace::autoclean;

use Wardrobe::Model::Outfit;
use Wardrobe::TemplateUtil (qw/cln/);

BEGIN {extends 'Catalyst::Controller'; }

Expand Down Expand Up @@ -66,12 +67,17 @@ sub add :Chained('tag_root') :PathPart('add') :Args(0) {
my $clothing_id = $c->req->params->{"clothing_id"};
my $outfit_name = $c->req->params->{"tag"};

if ($outfit_name eq '') {
$c->log->warn('User attempted to tag against an empty string');
$c->res->redirect($c->uri_for($c->controller('Clothes')->action_for('clothing'), $clothing_id, 'x'));
return;
}

my $outfit = Wardrobe::Model::Outfit->find_or_create_outfit($outfit_name);
Wardrobe::Model::Outfit->tag_clothing_to_outfit($outfit->outfit_id, $clothing_id);

my $fwd_url_part = $outfit->name;
$fwd_url_part =~ s/\///g;
$c->res->redirect("/tags/tag/" . $outfit->outfit_id . "/" . $fwd_url_part);
my $cln_name = Wardrobe::TemplateUtil::cln($outfit_name);
$c->res->redirect($c->uri_for('tag', $outfit->outfit_id, $cln_name));

}

Expand Down
21 changes: 19 additions & 2 deletions root/clothes/clothing.tt
Expand Up @@ -3,6 +3,23 @@
title = "Clothing Item: $item.name"
%]

<script type="text/javascript">

function validateTag() {

var tag_name = document.getElementById('tag_name').value;

if (tag_name == undefined || tag_name == '') {
alert('Must provide a tag name', "Will not Tag");
return false;
}

return true;

}

</script>

<div class="content">
<p>
This item is in the category: [% item.category.name | html %]
Expand All @@ -21,9 +38,9 @@
</p>
<p>
Tag this item of clothing as part of an outfit.<br />
<form method="post" action="[% c.uri_for(c.controller('Tags').action_for('add')) %]">
<form method="post" action="[% c.uri_for(c.controller('Tags').action_for('add')) %]" onsubmit="return validateTag()">
<input type="hidden" name="clothing_id" value="[% item.clothing_id %]" />
<input type="text" name="tag" />
<input type="text" name="tag" id="tag_name" />
<input type="submit" value="Tag!" />
</form>
</p>
Expand Down

0 comments on commit dddf773

Please sign in to comment.