Browse Source

first attempt at the form

master
Cristina Cochior 6 years ago
parent
commit
15cac0116e
  1. BIN
      .DS_Store
  2. 4
      config.py
  3. 11
      forms.py
  4. 28
      newstart.py
  5. 20
      templates/description.html
  6. 42
      templates/form-template.html
  7. 28
      templates/login.html

BIN
.DS_Store

Binary file not shown.

4
config.py

@ -0,0 +1,4 @@
import os
class Config(object):
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'

11
forms.py

@ -0,0 +1,11 @@
from flask_wtf import Form
from wtforms import TextField, IntegerField, TextAreaField, SubmitField, RadioField, SelectField, StringField
from wtforms import validators, ValidationError
class ReusableForm(Form):
name = TextField('Name:', [validators.Required('Please enter your name.')])
email = TextField('Email:',[validators.Required('Please enter your email address.'), validators.Email('Please enter your email address.')])
friend = RadioField('Are you a friend of De Player?', choices = [('Y','Yes'),('NY','Not Yet')])
content = StringField('Description:',[validators.Required('Please enter a description.')])
submit = SubmitField('Send')

28
newstart.py

@ -0,0 +1,28 @@
from wtforms import Form, TextField, BooleanField, StringField, SubmitField, validators
from flask import Flask, url_for, render_template, Markup, redirect, request, flash
from flask import session as login_session
from forms import ReusableForm
from config import Config
import json
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
app.config.from_object(Config)
@app.route('/', methods=['GET', 'POST'])
def description():
form = ReusableForm(request.form)
print (form.errors)
if request.method == 'POST' and form.validate():
return 'Success'
return render_template('description.html', form=form)
if __name__ == '__main__':
app.run(debug = True)

20
templates/description.html

@ -0,0 +1,20 @@
<!doctype html>
<html>
<body>
<h2 style = "text-align: center;">Write something very interesting here.</h2>
{% for message in form.name.errors %}
<div>{{ message }}</div>
{% endfor %}
<form method="POST" action="/write">
<fieldset>
{{ form.hidden_tag() }}
<div>{{ form.name.label }} {{ form.name }}</div>
<div>{{ form.email.label }} {{ form.email }}</div>
<div>{{ form.friend.label }} {{ form.friend }}</div>
<div>{{ form.content.label }} {{ form.content }}</div>
<div>{{ form.submit }}</div>
</fieldset>
</form>
</body>
</html>

42
templates/form-template.html

@ -0,0 +1,42 @@
{% block content %}
<div class="formwrapper">
<form method=post>
<div class="name">
{{ form.name(placeholder='Joe Blah') }} {{ form.name.label }}
{% if form.name.errors %}
<ul class="errors">{% for error in form.name.errors %}<li>{{ error }}</li>{% endfor %}</ul>
{% endif %}
</div>
<div class="email">
{{ form.email }} {{ form.email.label }}
{% if form.email.errors %}
<ul class="errors">{% for error in form.email.errors %}<li>{{ error }}</li>{% endfor %}</ul>
{% endif %}
</div>
<div class="password">
{{ form.password }} {{ form.password.label }}
{% if form.password.errors %}
<ul class="errors">{% for error in form.password.errors %}<li>{{ error }}</li>{% endfor %}</ul>
{% endif %}
</div>
<div class="confirm">
{{ form.confirm }} {{ form.confirm.label }}
{% if form.confirm.errors %}
<ul class="errors">{% for error in form.password.errors %}<li>{{ error }}</li>{% endfor %}</ul>
{% endif %}
</div>
<div class="website">
{{ form.website(placeholder='http://example.com') }} {{ form.website.label }}
</div>
<div class="submitbutton">
<input id="submit" type="submit" value="Submit">
</div>
</form>
</div>
{% for message in get_flashed_messages() %}
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ message }}
</div>
{% endfor %}

28
templates/login.html

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
{% if message %}
<p>{{ message }}</p>
{% endif %}
<form action="" method="post">
<p>
<label for="username">Username</label>
<input type="text" name="username">
</p>
<p>
<label for="password">Password</label>
<input type="password" name="password">
</p>
<p>
<input type="submit">
</p>
</form>
</body>
</html>
Loading…
Cancel
Save