From 2235b8dbec6c32487d55910043f778b29cdcff75 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 9 Jan 2018 22:39:48 +0100 Subject: [PATCH] Forms (#36) * init forms * docs about base form validation. * wip form submissions * kinda sorta more form data * last bit of formdata * implement forms feedback * merge form feedback * use currentTarget --- content/reference/forms.md | 312 +++++++++++++++++++++++++++++++++++ examples/form-data/index.js | 40 +++++ examples/form-data/server.js | 0 3 files changed, 352 insertions(+) create mode 100644 content/reference/forms.md create mode 100644 examples/form-data/index.js create mode 100644 examples/form-data/server.js diff --git a/content/reference/forms.md b/content/reference/forms.md new file mode 100644 index 0000000..8fa9ec0 --- /dev/null +++ b/content/reference/forms.md @@ -0,0 +1,312 @@ +# forms +Websites generally consist of 3 main elements: paragraph text, lists and forms. +While paragraph text is generally straight forward to place on a page, lists & +forms require some more work. This section explains everything you need to know +to work with forms in Choo. + +This guide assumes you're working from a project generated by `create-choo-app`. +This allows us to write inline CSS, which makes examples a little simpler to +read. However our goal is to provide you with knowledge that translates to any +setup - even if you don't end up using Choo. + +## How do forms work? +Before we dive into how forms work in Choo, let's dive into how forms work on +pages that don't use any JavaScript. A lot of the web was designed to work +without JavaScript, and to submit forms, you don't need any JS at all. Knowing +what the default behavior of forms is allows us to build on top of it, rather +than trying to rewrite functionality that's already available to us. + +### The Form Element +Forms are declared using the `
` tag. By themselves they don't do much, but +they have a few important attributes that are good to know about. + +The first attribute is `method=""`. This tells the form which HTTP method to +use. By default it's set to `POST`, so often it's not needed to define this. + +The second attribute is `action=""`. This attribute tells the form where to +redirect the page to when the submission was successful. + +Forms also always should have an `id=""` attribute on them. This makes them +easier to debug, and shows up in the payload that's sent to the server. + +```html + +
+``` + +### The Input Element +Forms need data. And `` elements provide that data. As a rule, each +`` element has a `type=""` attribute, and an accompanying `