<form>

<form> has been extended in Rapid to make it easier to construct and use forms with Hobo models. In addition to the base <form> tag, a form with contents is generated for each Hobo model. These are found in app/views/taglibs/auto/rapid/forms.dryml.

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 POST to 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 PUT to the update action. This is handled in a special way by Rails due to current browsers not supporting PUT, the method is set to POST with a hidden input called _method with a value of PUT. 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_token hidden field if forgery protection is enabled

  • Hobo inserts a page_path hidden 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 last_if if it does not have permission to display the form. The <else> clause may be used to display alternate content. For example:

    ... You do not have permission to edit this form

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

  • all AJAX 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.dryml that 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

Show Source


Edit this page