{"action":"created","issue":{"url":"https://api.github.com/repos/kapouer/express-dom/issues/10","repository_url":"https://api.github.com/repos/kapouer/express-dom","labels_url":"https://api.github.com/repos/kapouer/express-dom/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/kapouer/express-dom/issues/10/comments","events_url":"https://api.github.com/repos/kapouer/express-dom/issues/10/events","html_url":"https://github.com/kapouer/express-dom/issues/10","id":118574361,"number":10,"title":"smart form handling","user":{"login":"kapouer","id":131406,"avatar_url":"https://avatars.githubusercontent.com/u/131406?v=3","gravatar_id":"","url":"https://api.github.com/users/kapouer","html_url":"https://github.com/kapouer","followers_url":"https://api.github.com/users/kapouer/followers","following_url":"https://api.github.com/users/kapouer/following{/other_user}","gists_url":"https://api.github.com/users/kapouer/gists{/gist_id}","starred_url":"https://api.github.com/users/kapouer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kapouer/subscriptions","organizations_url":"https://api.github.com/users/kapouer/orgs","repos_url":"https://api.github.com/users/kapouer/repos","events_url":"https://api.github.com/users/kapouer/events{/privacy}","received_events_url":"https://api.github.com/users/kapouer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/kapouer/express-dom/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-24T10:16:03Z","updated_at":"2016-02-16T01:47:18Z","closed_at":null,"body":"The idea is to handle forms only using javascript in the client browser:\r\n- user input validation is done there, succeeds or fails\r\n- data is saved using HTTP API, possibly complex stuff happens\r\n- document.location is updated\r\n\r\nIn case of failure or success of the form validation, document.location is changed\r\nto reflect that the page state has changed.\r\n\r\nIt should be possible to tell the client page to populate (using trusted data from session api) and submit the form automatically. Such automation is driven by document.location.\r\n\r\nLet's consider a page with url /mypage, containing a form named \"myform\".\r\n\r\na) After the user has filled the form, clicking on submit should change document.location to\r\n/mypage?form=myform which in turn validates the form and post it using client side javascript.\r\nIn case of error or success, the client side javascript would update the form to show the error or success and change document.location to /mypage?status=400 or 404, 500, etc... (see also https://github.com/kapouer/express-dom/issues/8 about that).\r\nIt could also choose to go to another page, again with status parameter, or without.\r\nIn the client browser, the change in document.location can be done with or without History API.\r\n\r\nb) Now let's consider that the client browser does not have javascript enabled, opens /mypage, fill the form and submit it. The server receives a POST /mypage?form=myform with some data.\r\nIt is something that shouldn't happen (POST-ing to a web page - only POST-ing to HTTP API makes sense). In that case, the data should be saved to the session api (using as key /mypage?form=myform) and the web page should be opened on the server.\r\nThe first thing the web page sees is that the form isn't filled, tries to fill it.\r\nThe second thing is that the url triggers a submit, so it does exactly the same as a)\r\nThe server now sees how the form submission went (by tracking document.location changes), so it knows either what to display (the html content of the current page if it wasn't reloaded by client code,  which can happen if using History API) or where to redirect to (if the client code did a plain old document.location redirection, it is cancelled and redirection is sent as a reply to the original POST).\r\n\r\nThe result is that, by respecting a few principles for client-side form submission, we can automatically support pure html forms by emulating them on the hosted client.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/kapouer/express-dom/issues/comments/184471558","html_url":"https://github.com/kapouer/express-dom/issues/10#issuecomment-184471558","issue_url":"https://api.github.com/repos/kapouer/express-dom/issues/10","id":184471558,"user":{"login":"kapouer","id":131406,"avatar_url":"https://avatars.githubusercontent.com/u/131406?v=3","gravatar_id":"","url":"https://api.github.com/users/kapouer","html_url":"https://github.com/kapouer","followers_url":"https://api.github.com/users/kapouer/followers","following_url":"https://api.github.com/users/kapouer/following{/other_user}","gists_url":"https://api.github.com/users/kapouer/gists{/gist_id}","starred_url":"https://api.github.com/users/kapouer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kapouer/subscriptions","organizations_url":"https://api.github.com/users/kapouer/orgs","repos_url":"https://api.github.com/users/kapouer/repos","events_url":"https://api.github.com/users/kapouer/events{/privacy}","received_events_url":"https://api.github.com/users/kapouer/received_events","type":"User","site_admin":false},"created_at":"2016-02-16T01:47:18Z","updated_at":"2016-02-16T01:47:18Z","body":"See wiki, partially handled by client."}}