<form>
Usage
<form> can be used as a regular HTML tag:
<form action="/blog_posts/1" method="POST">...</form>
If no action attribute is provided then the context is used to construct an appropriate action using restful routing:
-
If the context is a new record then the form action will be a
POSTto the create action:<form with="&BlogPost.new">...</form> -> <form action="/blog_posts" method="POST">...</form> -
If the context is a saved record then the form action will be a
PUTto the update action. This is handled in a special way by Rails due to current browsers not supportingPUT, the method is set toPOSTwith a hidden input called_methodwith a value ofPUT. Hobo adds this automatically:<% blog_post = BlogPost.find(1) %> <form with="&blog_post">...</form> -> <form action="/blog_posts/1" method="POST"> <input id="_method" type="hidden" value="PUT" name="_method"/> ... </form>
AJAX based submission can be enabled by simply adding an update attribute. e.g.
<div part="comments"><collection:comments/></div>
<form with="&Comment.new" update="comments"/>
More information on Ajax can be viewed in the manual or in the Rapid Forms index.
Additional Notes
-
Hobo automatically inserts an
auth_tokenhidden field if forgery protection is enabled -
Hobo inserts a
page_pathhidden field in create / update forms which it uses to re-render the correct page if a validation error occurs. -
<form> supports all of the standrd ajax attributes - (see the main taglib docs for Rapid Forms)
-
<form> resets
... You do not have permission to edit this formlast_ifif it does not have permission to display the form. The <else> clause may be used to display alternate content. For example:
or on a standard generated page using a default form:
<some-page>
<after-form:>
<else>You do not have permission to edit this form</else>
</after-form:>
</some-page>
Attributes
-
action: the controller action. Default is create or update as appropriate
-
method: PUT or POST
-
web-method
-
lifecycle: specifies the name of a transition or creator. This attribute is an alternative to the action and method attributes. There should also be auto-generated forms in your
app/views/taglibs/auto/rapid/forms.drymlthat you may be able to use unchanged or with light customization. See the lifecycles manual for more information -
owner
-
multipart: if set, the encoding is set to multipart/form-data. The default is x-www-form-urlencoded
-
reset-form: Clear the form after submission (only makes sense for ajax forms)
-
refocus-form: Refocus the first form-field after submission (only makes sense for ajax forms)
-
before-unload: If set to a message, the message is displayed if the user attempts to leave the page without submitting the form. Note that some browsers ignore the user’s message and display their own in an attempt to stop mouse-trappers.
Parameters
The standard form tag does not have any parameters, nor does it have any default content. However, Hobo does autogenerate polymorphic form tags for each of your models into app/views/taglibs/auto/rapid/forms.dryml. These forms have the following parameters:
-
error-messages
-
field-list
-
actions
-
submit
-
cancel
Edit this page