diff options
| -rw-r--r-- | ideas.html | 41 | ||||
| -rw-r--r-- | main.go | 9 | 
2 files changed, 39 insertions, 11 deletions
| @@ -6,6 +6,9 @@      <title>Ideas</title>      <style> +body { +    margin-left: 1em; +}  .idea {      border: solid 2px black;       border-radius: 5px; @@ -41,6 +44,23 @@  .error {      color: red;  } +textarea[name="text"] { +    border: solid 2px black; +    border-radius: 5px; +    margin-top: .3em; +    margin-bottom: .3em; +    resize: none; +} +h3 { +    margin-bottom: 0; +} +input[type="text"]{ +    border-radius: 3px; +    border: solid 1px black; +} +input[name="author"] { +    margin-bottom: .3em; +}      </style>  </head> @@ -48,16 +68,13 @@      {{ with .Error }}      <p class="error">{{.}}</p>      {{ end}} +    <h3>Add an idea:</h3>      <form action="/create/" method="post"> -        <input name="title"  type="text" placeholder="Title"></br> -        <input name="text"   type="text" placeholder="Idea description..."></br> -        <input name="author" type="text" placeholder="Your Name"></br> -        <input type="submit" value="Post"> -    </form> -    <hr> -    <form action="/delete/" method="post"> -        <input type="text" placeholder="Title" name="title"></br> -        <input type="submit" value="Delete"> +        <input name="title" type="text" placeholder="Title" required></br> +        <textarea name="text" cols=50 rows=4 placeholder="Write what is in your lightbulb here." required></textarea> +        </br> +        <input name="author" type="text" placeholder="Your Name" required></br> +        <input type="submit" value="Think">      </form>      <hr>      <ul> @@ -66,7 +83,13 @@              <h2 class="title">{{.Title}}</h2>              <p class="text">{{.Text}}</p>              <p class="creation">by <span class="author">{{.Author}}</span> on <span class="date">{{.CreatedAt}}</span></p> +            <form action="/delete/" method="post"> +                <input type="hidden" name="title" value="{{.Title}}"> +                <input type="submit" value="delete"> +            </form>          </div> +    {{ else }} +    <p><i>No ideas here... Be the first one to think!</i></p>      {{ end }}      </ul>      <!--template--> @@ -30,12 +30,13 @@ var ideas_html string  var Ideas []Idea  // ToDo's -// - [ ] Add a post -// - [ ] Remove a post +// - [x] Add a post +// - [x] Remove a post  // - [ ] work with funcmaps in templates  // - [ ] Put a reaction on a post  // - [x] Store ideas to a file (encoder/gob)  // - [x] Change the date format printing +// - [x] outsource removing the posts to a separate cli tool  // Represents an idea  // CreatedAt is a formatted date string @@ -166,6 +167,10 @@ func main() {  			CreatedAt: time.Now().Format(DateLayout),  			Text:      r.FormValue("text"),  		} +		if i.Title == "" || i.Author == "" || i.Text == "" { +			tmpl.Execute(w, PageData{Ideas, "All fields are required"}) +			return +		}  		for _, v := range Ideas {  			if i.Title == v.Title { | 
