The problem
I encountered unexpected behaviour when attempting a basic form submit. When the form was submitted two calls to the server were made and two objects were created in the datastore.
Expected behaviour
The form’s values are sent to the server associated with the /create
URL, an object is created and persisted to the datastore and the application opens a page where the user can add additional information to the newly created object.
The form
1 |
<form id="create-form" action="/create" method="post"><br /> <fieldset><br /> <legend>Create</legend><br /> <label for="name-field">Name</label><br /> <input id="name-field" name="name-field" type="text" value="" /><br /><br /> <label for="tag-field">Tags</label><br /> <input id="tag-field" name="tag-field" type="text" value="" /><br /><br /> <input class="add-button" type="submit" value="Create" /><br /> </fieldset><br /></form> |
The issue
While the behaviour was triggered by form submission, the issue was actually associated with how the application rendered the view after submission. The page loaded after form submission included a Facebox. Facebox initialization causes a second set of requests on load. So, if posting to /create
, Facebox will start a second set of requests with the base URL set to /create
. A fix is to redirect to a URL which handles get requests after doing a post, in this way the server hit in the initial submission is not requested twice.