Speed up development with full-stack environments for every branch.

Learn More

Simple form validation [Python and Django]

4650 Runs 14611 Views 3202 Copies
Saved

Saved

magicjohnson 10

magicjohnson
published 4 years ago

    <html>
    <head>
      <title>Form validation example</title>
      <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css">
    </head>
    <body>
    
      <div class="col-sm-8">
        <h2>Form validation example</h2>
        {% if form.errors %}
        <div class="text-danger">Please correct the error{{ form.errors|pluralize }} below.</div>
        {% endif %}
        <p>
        <div class="form-horizontal">
          <form action="" method="post" role="form">{% csrf_token %}
    
            <div class="form-group row {% if form.subject.errors %}has-error{% endif %}">
               <label for="id_subject" class="col-sm-3 control-label">Email subject:</label>
               <div class="col-lg-5">
                {{ form.subject }}
                {% if form.subject.errors %}
                  <span class="help-block">
                    {% for error in form.subject.errors %}{{ error }}{% endfor %}
                  </span>
                {% endif %}
              </div>
            </div>
    
            <div class="form-group row {% if form.email.errors %}has-error{% endif %}">
              <label for="id_sender" class="col-sm-3 control-label">Email address:</label>
              <div class="col-lg-5">
              {{ form.email }}
                {% if form.email.errors %}
                  <span class="help-block">
                    {% for error in form.email.errors %}{{ error }}{% endfor %}
                  </span>
                {% endif %}
              </div>
            </div>
            
            <div class="form-group row {% if form.message.errors %}has-error{% endif %}">
              <label for="id_message" class="col-sm-3 control-label">Message:</label>
              <div class="col-lg-5">
                {{ form.message }}
                {% if form.message.errors %}
                  <span class="help-block">
                    {% for error in form.message.errors %}{{ error }}{% endfor %}
                  </span>
                {% endif %}
              </div>
            </div>
    
            <div class="form-group row">
              <div class="col-sm-5 col-sm-offset-3">
                <input type="submit" value="Validate form" class="btn btn-primary" />
              </div>
            </div>
          </form>
        </div>
      </div>
    </body>
    </html>
    Please login/signup to get access to the terminal.

    Your session has timed out.

    Dismiss (the page may not function properly).