<form action="???" method="POST">
<input type="text" name="content">
</form>
Suppose I’m using Backbone.js’s “routes” feature, and I build dynamic web apps.
Let’s say I want to implement a normal form. When the user submits something, how would that work?
- if there’s an error while validating server side, how do I display the form again? (I don’t need or want to validate using Ajax or anything…that overcomplicates things. Server side validation is good enough.)
- if it’s successful, how do I render another template? Do I redirect to (/#/success?”)
I understand how Backbone.js works with anchor links (using the routes #) , but I can’t wrap my head around best practices with forms and backbone.js
If your site is using the hash fragment, you probably want to do submit your forms using AJAX, rather than a full page reload using a POST.
I would use jQuery.post, with a custom success and error handler that you can control from your JavaScript, to redirect to a hash.