Back to Examples Run this application locally to try examples


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)


[[extend 'layout.html']]

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

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

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