form

An article by Gaspard Bucher

Announce a form which will be used for ajax calls.

  1. action
  2. ajax
  3. API
  4. classes
  5. common attributes
  6. conditions
  7. context
  8. dates
  9. display
  10. forms
    1. captcha
    2. checkbox
    3. form
    4. input
    5. new
    6. radio
    7. select
    8. textarea
  11. i18n
  12. meta
  13. SQLiss
  14. urls

Announce a form which will be used for ajax calls.

  • publish Set whether to auto-publish node after save.
  • klass set the class of newly created nodes
  • mode redirect page mode
  • update dom_id to update after operation
  • t_id id of node used to render ajax template
see add, drop, each, edit, input, name, new, publish, remote update
<r:form mode='team'><form>
  <ul>
    <li><b>select team members</b></li>
    <li><r:checkbox name='mate_ids' nodes='contacts in site'/></li>
    <li><r:input type='submit'/></li>
  </ul>
</form></r:form>

<h3>drop updates icon, with form</h3>
<div do='drop' change='params' d='[id]' do='if' test='param:d'>
  <r:node where='id eq param:d' in='site'>
    Change icon to <r:img mode='tiny'/> ?
    <r:form t_id='[main.id]'>
      <r:input type='hidden' name='icon_for_id' set_value='[main.id]'/>
      <r:input type='hidden' name='m_title' set_value='becoming icon for [main.name]'/>
      <r:textarea name='m_text'/>
      <input type='submit'/>
    </r:form>
  </r:node>
  <r:else>
    please drop a node to change the icon
    <r:icon>
      <r:img mode='pv'/>
      <ul do='comments'>
        <li do='each'>
          <b do='[title]'/> <b do='[author_name]'/>
          <div do='{text}'/>
        </li>
      </ul>
    </r:icon>
  </r:else>
</div>

You can omit the <form> element and it will be added to wrap the content but there are cases where you definitely need both: declare the whole form and place the actual form elements. For example:

<table do='mates'>
  <tr do='each'><td do='link'/></tr>
  <tr do='form'><td><form>...</form></td></tr>
  <tr do='add'><td><r:add_btn/></td></tr>
</table>

automatic fields

Whether you use forms in ajax contexts or to update/create new elements without javascript, the necessary fields to create the correct objects and/or to render the proper partials are automatically inserted.

There is one field that is necessary to create any Node: parent_id. When no input or select exists for this field Zafu sets the parent_id to the node context before new.

redirection

If you want the form to redirect after create/update, set the “redir” parameter:

<r:form>...
  <input type='hidden' name='redir' value='#{zen_path(main, :mode =&gt; 'foo')}'/>
</r:form>

Yes, you have to use the ”&gt;” text instead of ”>” (amp, ‘g’, ‘t’, ’;’).

You can also use the “mode” parameter to redirect to the node’s page with the given mode.