Skip to content

Instantly share code, notes, and snippets.

@efazati
Created February 22, 2014 07:28
Show Gist options
  • Save efazati/9150052 to your computer and use it in GitHub Desktop.
Save efazati/9150052 to your computer and use it in GitHub Desktop.
jinja form_maker
{% macro form_maker(form, title) -%}
<div class='content_block_title'>{{ _("Form") }} {{title}}</div>
<div class="form ">
<form method="post" class="contact {% if form_class %}{{form_class}}{% endif %}" action="{{form.action}}" enctype="multipart/form-data" >
{% for field in form %}
{% if field.type == 'CSRFTokenField' %}
{{field}}
{% elif field.type == 'FieldList' %}
<h3>{{field.label}}</h3>
{{field}}
{% else %}
<div class="form-row control-group row-fluid">
<label class="control-label span12" for="with-placeholder">{{field.title}}
{% if field.errors %}
{% for error in field.errors %}
<span class="help-block label label-important">{{error}}</span>
{% endfor %}
{% elif field.validators %}
*
{% endif %}
</label>
{% if field.type == 'TextAreaField' %}
<div class="controls span11">
{% else %}
<div class="controls span6">
{% endif %}
{{ field(class="row-fluid form-control",placeholder=_(field.title))|safe }}
</div>
</div>
{% endif %}
{% endfor %}
{% for name, label in buttons %}
<div class="field">
<input type="submit" name="{{name}}" value="{{label}}"/>
</div>
{% endfor %}
<input type="hidden" name="csrf" value="{{form.csrf}}"/>
<div class="edit button">
<input class="submit btn btn-primary" type="submit" name="submit" value="{{ _('submit')}}"/>
</div>
</form>
</div>
{%- endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment