Back to Examples Run this application locally to try examples

examples/custom_form.py

from py4web import action
from py4web.utils.form import Form, FormStyleDefault

from .common import T, db, session


@action("custom_form", method=["GET", "POST"])
@action.uses("examples/custom_form.html", db, session, T)
def custom_form(id=None):
    form = Form(db.person, id, deletable=False, formstyle=FormStyleDefault)
    rows = db(db.person).select()
    return dict(form=form, rows=rows)

templates/examples/custom_form.html

[[extend 'layout.html']]

<h2 class="title">Form Superhero Identity (Custom) </h2>
[[= form.custom.begin ]]
  <div class="columns is-bordered">
    <div class="column">
      <label>Name:</label>
      [[= form.custom.widgets['name'] ]]
      <span style="color:#ff0000">[[= form.custom.errors.get('name', '') ]]</span>
    </div>
    <div class="column">
      <label>Job:</label>
      [[= form.custom.widgets['job'] ]]
      <span style="color:#ff0000">[[= form.custom.errors.get('job', '')]]</span>
    </div>
    <div class="column">
      <div class="buttons is-centered">
        [[ form.custom.submit['_class'] = 'button is-info is-large' ]]
        [[= form.custom.submit ]]
      </div>
    </div>
  </div>
[[= form.custom.end ]]


<h2 class="title">Rows</h2>

<ul>
  [[for row in rows:]]
  <li>[[=row.id]]: [[=row.name]] ([[=row.job]])</li>
  [[pass]]
</ul>