Last active
January 20, 2016 12:58
-
-
Save johnschimmel/3859513 to your computer and use it in GitHub Desktop.
sample form with flask-mongoengine wtform validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="POST" role="form"> | |
{{ form.csrf_token }} | |
<legend><h3>Share Your Ideas</h3></legend> | |
{% if form.errors %} | |
<ul class="errors"> | |
{% for field_name, field_errors in form.errors|dictsort if field_errors %} | |
{% for error in field_errors %} | |
<li>{{ form[field_name].label }}: {{ error }}</li> | |
{% endfor %} | |
{% endfor %} | |
</ul> | |
{% endif %} | |
<div class="form-group"> | |
{{ form.creator.label() }} | |
{{ form.creator(class='form-control', type='textinput') }} | |
<!-- | |
<label for="creator">First Name</label> | |
<input type="text" id="creator" name="creator" class="form-control" value=""> | |
--> | |
</div> | |
<div class="form-group"> | |
{{ form.title.label() }} | |
{{ form.title(class='form-control', type='textinput') }} | |
<!-- | |
<label for="title">Project Title</label> | |
<input type="text" id="title" name="title" class="form-control"> | |
--> | |
</div> | |
<div class="form-group"> | |
{{ form.idea.label() }} | |
{{ form.idea(class='form-control', type='textarea') }} | |
<!-- <label for="idea">Idea description</label> | |
<textarea name="idea" id="idea" class="form-control"></textarea> | |
--> | |
</div> | |
<label>Category</label> | |
<p class="help-block">Select as many as you need.</p> | |
{# comment - loop through categories and create checkboxes #} | |
{% for c in categories|sort %} | |
<div class="checkbox"> | |
<label> | |
<input type="checkbox" \ | |
name="categories" | |
value="{{ c|replace(" ","_") }}" {% if c|replace(" ","_") in form.categories.data %}checked=checked{% endif %}> | |
{{ c|title }} | |
</label> | |
</div> | |
{% endfor %} | |
<button type="submit" class="btn btn-primary">Add Idea</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment