{"action":"created","comment":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/75199655","id":75199655,"diff_hunk":"@@ -75,7 +75,108 @@ __required__\n \n Action must be provided, `https` and is non-cdn link (does **NOT** link to https://cdn.ampproject.org).\n \n+**action-xhr**\n+__optional__\n+You can also provide an action-xhr attribute, if provided, the form will be submitted in an XHR fashion.\n+\n+This attribute can be the same or a different endpoint that action and has the same action requirement above.\n+\n+**Important**: Your XHR endpoints need to follow and implement [CORS Requests in AMP spec](https://github.com/ampproject/amphtml/blob/master/spec/amp-cors-requests.md).\n+\n All other [form attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) are optional.\n \n ## Inputs\n Currently, `<input type=button>`, `<input type=file>`, `<input type=image>` and `<input type=password>` are not allowed. (This might be reconsidered in the future - please let us know if you require these and use cases).\n+\n+## Events\n+`amp-form` exposes 3 events:\n+**submit**\n+Emitted whenever the form is submitted and before the submission is complete.\n+\n+**submit-success**\n+Emitted whenever the form submission is done and response is a success.\n+\n+**submit-error**\n+Emitted whenever the form submission is done and response is an error.\n+\n+These events can be used through the [on attribute](https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#on).\n+For example, the following listens to both submit success and submit error and shows different lightboxes depending on the event\n+\n+```html\n+<form ... on=\"submit-success:success-lightbox;submit-error:error-lightbox\" ...>\n+</form>\n+```\n+\n+See the [full example here](https://github.com/ampproject/amphtml/blob/master/examples/forms.amp.html).\n+\n+## Success/Error Response Rendering\n+`amp-form` allows publishers to render the responses using [Extended Templates](https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#extended-templates).\n+\n+Using `submit-success` and `submit-error` special marker attributes, publishers can mark any **child element of form** and include a `<template></template>` tag inside it to render the response in it.\n+\n+The response is expected to be a valid JSON Object. For example, if the publisher's `action-xhr` endpoint returns the following responses:\n+\n+**Success Response**\n+```json\n+{\n+  \"name\": \"Jane Miller\",\n+  \"interests\": [{\"name\": \"Basketball\"}, {\"name\": \"Swimming\"}, {\"name\": \"Reading\"}],\n+  \"email\": \"email@example.com\"\n+}\n+```\n+\n+**Error Response**\n+```json\n+{\n+  \"name\": \"Jane Miller\",\n+  \"message\": \"The email (email@example.com) you used is already subscribed.\"\n+}\n+```\n+\n+Publishers can render these in a template inside their forms as follow.\n+\n+```html\n+<form ...>\n+    <fieldset>\n+      ...\n+    </fieldset>\n+    <div submit-success>\n+        <template type=\"amp-mustache\">\n+            Success! Thanks {{name}} for subscribing! Please make sure to check your email {{email}}\n+            to confirm! After that we'll start sending you weekly articles on {{#interests}}<b>{{name}}</b> {{{{/interests}}.\n+        </template>\n+    </div>\n+    <div submit-error>\n+        <template type=\"amp-mustache\">\n+            Oops! {{name}}, {{message}}.\n+        </template>\n+    </div>\n+</form>\n+```\n+\n+See the [full example here](https://github.com/ampproject/amphtml/blob/master/examples/forms.amp.html).\n+\n+## Polyfills\n+`amp-form` polyfill behaviors and functionality missing from some browsers or being implemented in the next version of CSS.","path":"extensions/amp-form/amp-form.md","position":null,"original_position":86,"commit_id":"ecfacaac8ae2b64848bdc15614c04600276e8e31","original_commit_id":"183d6016de4ea54ffba325d047a4e7e91ce9a8e1","user":{"login":"mkhatib","id":2647,"avatar_url":"https://avatars.githubusercontent.com/u/2647?v=3","gravatar_id":"","url":"https://api.github.com/users/mkhatib","html_url":"https://github.com/mkhatib","followers_url":"https://api.github.com/users/mkhatib/followers","following_url":"https://api.github.com/users/mkhatib/following{/other_user}","gists_url":"https://api.github.com/users/mkhatib/gists{/gist_id}","starred_url":"https://api.github.com/users/mkhatib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkhatib/subscriptions","organizations_url":"https://api.github.com/users/mkhatib/orgs","repos_url":"https://api.github.com/users/mkhatib/repos","events_url":"https://api.github.com/users/mkhatib/events{/privacy}","received_events_url":"https://api.github.com/users/mkhatib/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2016-08-17T20:24:42Z","updated_at":"2016-08-17T20:24:42Z","html_url":"https://github.com/ampproject/amphtml/pull/4485#discussion_r75199655","pull_request_url":"https://api.github.com/repos/ampproject/amphtml/pulls/4485","_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/75199655"},"html":{"href":"https://github.com/ampproject/amphtml/pull/4485#discussion_r75199655"},"pull_request":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/4485"}}},"pull_request":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/4485","id":81069688,"html_url":"https://github.com/ampproject/amphtml/pull/4485","diff_url":"https://github.com/ampproject/amphtml/pull/4485.diff","patch_url":"https://github.com/ampproject/amphtml/pull/4485.patch","issue_url":"https://api.github.com/repos/ampproject/amphtml/issues/4485","number":4485,"state":"open","locked":false,"title":"Update amp-form docs and add an expanded note on CORS security.","user":{"login":"mkhatib","id":2647,"avatar_url":"https://avatars.githubusercontent.com/u/2647?v=3","gravatar_id":"","url":"https://api.github.com/users/mkhatib","html_url":"https://github.com/mkhatib","followers_url":"https://api.github.com/users/mkhatib/followers","following_url":"https://api.github.com/users/mkhatib/following{/other_user}","gists_url":"https://api.github.com/users/mkhatib/gists{/gist_id}","starred_url":"https://api.github.com/users/mkhatib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkhatib/subscriptions","organizations_url":"https://api.github.com/users/mkhatib/orgs","repos_url":"https://api.github.com/users/mkhatib/repos","events_url":"https://api.github.com/users/mkhatib/events{/privacy}","received_events_url":"https://api.github.com/users/mkhatib/received_events","type":"User","site_admin":false},"body":"ITI: #3343 ","created_at":"2016-08-12T05:33:57Z","updated_at":"2016-08-17T20:24:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e714590b5a48c296ab49ecec9434878b89adcde2","assignee":{"login":"erwinmombay","id":354746,"avatar_url":"https://avatars.githubusercontent.com/u/354746?v=3","gravatar_id":"","url":"https://api.github.com/users/erwinmombay","html_url":"https://github.com/erwinmombay","followers_url":"https://api.github.com/users/erwinmombay/followers","following_url":"https://api.github.com/users/erwinmombay/following{/other_user}","gists_url":"https://api.github.com/users/erwinmombay/gists{/gist_id}","starred_url":"https://api.github.com/users/erwinmombay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erwinmombay/subscriptions","organizations_url":"https://api.github.com/users/erwinmombay/orgs","repos_url":"https://api.github.com/users/erwinmombay/repos","events_url":"https://api.github.com/users/erwinmombay/events{/privacy}","received_events_url":"https://api.github.com/users/erwinmombay/received_events","type":"User","site_admin":false},"assignees":[{"login":"erwinmombay","id":354746,"avatar_url":"https://avatars.githubusercontent.com/u/354746?v=3","gravatar_id":"","url":"https://api.github.com/users/erwinmombay","html_url":"https://github.com/erwinmombay","followers_url":"https://api.github.com/users/erwinmombay/followers","following_url":"https://api.github.com/users/erwinmombay/following{/other_user}","gists_url":"https://api.github.com/users/erwinmombay/gists{/gist_id}","starred_url":"https://api.github.com/users/erwinmombay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erwinmombay/subscriptions","organizations_url":"https://api.github.com/users/erwinmombay/orgs","repos_url":"https://api.github.com/users/erwinmombay/repos","events_url":"https://api.github.com/users/erwinmombay/events{/privacy}","received_events_url":"https://api.github.com/users/erwinmombay/received_events","type":"User","site_admin":false},{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},{"login":"rudygalfi","id":3888212,"avatar_url":"https://avatars.githubusercontent.com/u/3888212?v=3","gravatar_id":"","url":"https://api.github.com/users/rudygalfi","html_url":"https://github.com/rudygalfi","followers_url":"https://api.github.com/users/rudygalfi/followers","following_url":"https://api.github.com/users/rudygalfi/following{/other_user}","gists_url":"https://api.github.com/users/rudygalfi/gists{/gist_id}","starred_url":"https://api.github.com/users/rudygalfi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudygalfi/subscriptions","organizations_url":"https://api.github.com/users/rudygalfi/orgs","repos_url":"https://api.github.com/users/rudygalfi/repos","events_url":"https://api.github.com/users/rudygalfi/events{/privacy}","received_events_url":"https://api.github.com/users/rudygalfi/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ampproject/amphtml/pulls/4485/commits","review_comments_url":"https://api.github.com/repos/ampproject/amphtml/pulls/4485/comments","review_comment_url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ampproject/amphtml/issues/4485/comments","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/ecfacaac8ae2b64848bdc15614c04600276e8e31","head":{"label":"mkhatib:forms-cors-security-docs","ref":"forms-cors-security-docs","sha":"ecfacaac8ae2b64848bdc15614c04600276e8e31","user":{"login":"mkhatib","id":2647,"avatar_url":"https://avatars.githubusercontent.com/u/2647?v=3","gravatar_id":"","url":"https://api.github.com/users/mkhatib","html_url":"https://github.com/mkhatib","followers_url":"https://api.github.com/users/mkhatib/followers","following_url":"https://api.github.com/users/mkhatib/following{/other_user}","gists_url":"https://api.github.com/users/mkhatib/gists{/gist_id}","starred_url":"https://api.github.com/users/mkhatib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkhatib/subscriptions","organizations_url":"https://api.github.com/users/mkhatib/orgs","repos_url":"https://api.github.com/users/mkhatib/repos","events_url":"https://api.github.com/users/mkhatib/events{/privacy}","received_events_url":"https://api.github.com/users/mkhatib/received_events","type":"User","site_admin":false},"repo":{"id":49671997,"name":"amphtml","full_name":"mkhatib/amphtml","owner":{"login":"mkhatib","id":2647,"avatar_url":"https://avatars.githubusercontent.com/u/2647?v=3","gravatar_id":"","url":"https://api.github.com/users/mkhatib","html_url":"https://github.com/mkhatib","followers_url":"https://api.github.com/users/mkhatib/followers","following_url":"https://api.github.com/users/mkhatib/following{/other_user}","gists_url":"https://api.github.com/users/mkhatib/gists{/gist_id}","starred_url":"https://api.github.com/users/mkhatib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkhatib/subscriptions","organizations_url":"https://api.github.com/users/mkhatib/orgs","repos_url":"https://api.github.com/users/mkhatib/repos","events_url":"https://api.github.com/users/mkhatib/events{/privacy}","received_events_url":"https://api.github.com/users/mkhatib/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mkhatib/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/mkhatib/amphtml","forks_url":"https://api.github.com/repos/mkhatib/amphtml/forks","keys_url":"https://api.github.com/repos/mkhatib/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mkhatib/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mkhatib/amphtml/teams","hooks_url":"https://api.github.com/repos/mkhatib/amphtml/hooks","issue_events_url":"https://api.github.com/repos/mkhatib/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/mkhatib/amphtml/events","assignees_url":"https://api.github.com/repos/mkhatib/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/mkhatib/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/mkhatib/amphtml/tags","blobs_url":"https://api.github.com/repos/mkhatib/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mkhatib/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mkhatib/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/mkhatib/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mkhatib/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/mkhatib/amphtml/languages","stargazers_url":"https://api.github.com/repos/mkhatib/amphtml/stargazers","contributors_url":"https://api.github.com/repos/mkhatib/amphtml/contributors","subscribers_url":"https://api.github.com/repos/mkhatib/amphtml/subscribers","subscription_url":"https://api.github.com/repos/mkhatib/amphtml/subscription","commits_url":"https://api.github.com/repos/mkhatib/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/mkhatib/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/mkhatib/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/mkhatib/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/mkhatib/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/mkhatib/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mkhatib/amphtml/merges","archive_url":"https://api.github.com/repos/mkhatib/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mkhatib/amphtml/downloads","issues_url":"https://api.github.com/repos/mkhatib/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/mkhatib/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/mkhatib/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/mkhatib/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mkhatib/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/mkhatib/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/mkhatib/amphtml/deployments","created_at":"2016-01-14T20:05:58Z","updated_at":"2016-01-14T20:06:00Z","pushed_at":"2016-08-17T20:24:08Z","git_url":"git://github.com/mkhatib/amphtml.git","ssh_url":"git@github.com:mkhatib/amphtml.git","clone_url":"https://github.com/mkhatib/amphtml.git","svn_url":"https://github.com/mkhatib/amphtml","homepage":"https://ampproject.org","size":141182,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ampproject:master","ref":"master","sha":"35e72c0237461af2e586a8826f7d530865d7ab6d","user":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"repo":{"id":41766002,"name":"amphtml","full_name":"ampproject/amphtml","owner":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ampproject/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":false,"url":"https://api.github.com/repos/ampproject/amphtml","forks_url":"https://api.github.com/repos/ampproject/amphtml/forks","keys_url":"https://api.github.com/repos/ampproject/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ampproject/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ampproject/amphtml/teams","hooks_url":"https://api.github.com/repos/ampproject/amphtml/hooks","issue_events_url":"https://api.github.com/repos/ampproject/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/ampproject/amphtml/events","assignees_url":"https://api.github.com/repos/ampproject/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/ampproject/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/ampproject/amphtml/tags","blobs_url":"https://api.github.com/repos/ampproject/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ampproject/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ampproject/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/ampproject/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/ampproject/amphtml/languages","stargazers_url":"https://api.github.com/repos/ampproject/amphtml/stargazers","contributors_url":"https://api.github.com/repos/ampproject/amphtml/contributors","subscribers_url":"https://api.github.com/repos/ampproject/amphtml/subscribers","subscription_url":"https://api.github.com/repos/ampproject/amphtml/subscription","commits_url":"https://api.github.com/repos/ampproject/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/ampproject/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/ampproject/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/ampproject/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/ampproject/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/ampproject/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ampproject/amphtml/merges","archive_url":"https://api.github.com/repos/ampproject/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ampproject/amphtml/downloads","issues_url":"https://api.github.com/repos/ampproject/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/ampproject/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/ampproject/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/ampproject/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ampproject/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/ampproject/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/ampproject/amphtml/deployments","created_at":"2015-09-01T22:10:53Z","updated_at":"2016-08-17T19:57:44Z","pushed_at":"2016-08-17T20:24:09Z","git_url":"git://github.com/ampproject/amphtml.git","ssh_url":"git@github.com:ampproject/amphtml.git","clone_url":"https://github.com/ampproject/amphtml.git","svn_url":"https://github.com/ampproject/amphtml","homepage":"https://ampproject.org","size":166908,"stargazers_count":8229,"watchers_count":8229,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":1187,"mirror_url":null,"open_issues_count":678,"forks":1187,"open_issues":678,"watchers":8229,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/4485"},"html":{"href":"https://github.com/ampproject/amphtml/pull/4485"},"issue":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/4485"},"comments":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/4485/comments"},"review_comments":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/4485/comments"},"review_comment":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/4485/commits"},"statuses":{"href":"https://api.github.com/repos/ampproject/amphtml/statuses/ecfacaac8ae2b64848bdc15614c04600276e8e31"}}}}
{"actor":{"display_login":"mkhatib"}}