Form sending value rather than name in html - html

This is my html code:
<form id="commentform" action="." method="post">
{% csrf_token %}
<label for="comment">Comment</label>
<textarea></textarea>
<div class="clearfix"></div>
<input type="submit" id="submit" name="body" value="send">
<div class="clearfix"></div>
</form>
I'm using this form to send data but instead of sending any input from user it always sends "Send" to server. How to cope with it, any help will be appreciated.

Try adding a name="" as a textarea attribute.
Try using:
<form id="commentform" action="." method="post">
{% csrf_token %}
<label for="comment">Comment</label>
<textarea name="textarea"></textarea>
<div class="clearfix"></div>
<input type="submit" id="submit" name="submit" value="Send">
<div class="clearfix"></div>
</form>

Related

Django templates: HTML validation errors

I'm running my code through validator and it's coming back with four errors which I don't know how to fix as the code has been imported from django forms.
Does anyone know how to fix these?
<div class="form-group">
<form method="POST">
<input type="hidden" name="csrfmiddlewaretoken" value="...">
<p><label for="id_username">Username:</label> <input type="text" name="username" maxlength="150" autofocus class="form-control" required id="id_username"> <span class="helptext">Required. 150 characters or
fewer. Letters, digits and #/./+/-/_ only.</span></p>
<p><label for="id_first_name">First name:</label> <input type="text" name="first_name" class="form-control" maxlength="100" required id="id_first_name"></p>
<p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" class="form-control" maxlength="100" required id="id_last_name"></p>
<p><label for="id_email">Email:</label> <input type="email" name="email" required id="id_email"></p>
<p><label for="id_password1">Password:</label> <input type="password" name="password1" autocomplete="new-password" class="form-control" required id="id_password1"> <span class="helptext">
<ul>
<li>Your password can’t be too similar to your other personal information.</li>
<li>Your password must contain at least 8 characters.</li>
<li>Your password can’t be a commonly used password.</li>
<li>Your password can’t be entirely numeric.</li>
</ul>
</span></p>
<p><label for="id_password2">Password confirmation:</label> <input type="password" name="password2" autocomplete="new-password" class="form-control" required id="id_password2"> <span class="helptext">Enter the same password as before, for verification.</span></p>
<div class="d-grid">
<button class="btn btn-dark ">Register</button>
</div>
</form>
</div>
I have used:
from django import forms
and in my views.py file I used:
from .forms import SignUpForm
my register.html page is as following:
{% extends 'base.html' %}
{% block title %}Register{% endblock %}
{% block content %}
<h1 class="my-4">Register</h1>
<div class="form-group">
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<div class="d-grid">
<button class="btn btn-dark ">Register</button>
</div>
</form>
</div>
{% endblock %}

How to change the default registration in django

I have used django's default registration. I want to edit this forms because it's appearance does not look very good to me. I want to convert the instructions into tool tip or something better looking how can I do it?I am new to django
)
html
<div class="header-wrapper">
<div class="header" style="background-image: url('/static/img/tele-bg.jpg');">
<div class="title-container text-center">
<h2>Register</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
</div>
</div>
For this you can use django bootstrap forms or you can make your own custom tempalate for registering the user.
If you want django bootstrap form which are pretty good you can try like this:
First install pip install django-bootstrap4
Then add the bootstrap4 into your INSTALLED_APPS:
INSTALLED_APPS = [
...........
'bootstrap4',]
Then you can render the forms in your template with this tag:
{% load bootstrap4 %}
<div class="header-wrapper">
<div class="header" style="background-image: url('/static/img/tele-bg.jpg');">
<div class="title-container text-center">
<h2>Register</h2>
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
</div>
</div>
EDIT: This is just a demo you can change this design as you want:
<div class="header-wrapper">
<div class="header" style="background-image: url('/static/img/tele-bg.jpg');">
<div class="title-container text-center">
<h2>Register</h2>
<form method="post">
{% csrf_token %}
Username:<br>
<input type="text" name="username" placeholder="Username"><br>
Password:<br>
<input type="password" name="password1" placeholder="Password"><br>
Password Confirmation:<br>
<input type="password" name="password2" placeholder="Confirm Password"><br><br>
<input type="submit" value="Submit">
</form>
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
</div>
</div>

Register button not working in registration_form.html django

I've been following the How to Django 1.9 tutorials and I came across a problem. My registration_form.html has been working properly ever since installment but after adding bootstrap to the template, the registration button has no action. This is the registration_form.html without the bootstrap
{% extends "rango/base.html" %}
{% block body_block %}
<h1>Register Here</h1>
<form method="post" action=".">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
{% endblock %}
This is the registration_template with the bootstrap
{% extends 'rango/base.html' %}
{% block body_block %}
<link href="http://v4-alpha.getbootstrap.com/examples/signin/signin.css" rel="stylesheet">
<div class="jumbotron">
<h1 class="display-5">Register</h1>
</div>
<form role="form" method='post' action='.'>
{% csrf_token %}
<div class="form-group">
<p class="required"><label class="required" for="id_username">Username:</label>
<input class="form-control" id="id_username" maxlength="30" name="username" type="text" />
<span class="helptext">
Required. 30 charachters or fewer. Letters, digits and #/./+/-/_ only.
</span>
</p>
<p class="required"><label class="required" for="id_email">Email:</label>
<input class="form-control" id="id_email" name="email" type="email"/>
</p>
<p class="required"><label class="required" for="id_password1">Password:</label>
<input class="form-control" id="id_password1" name="password1" type="password"/>
</p>
<p class="required"><label class="required" for="id_password2">Password Confirmation:</label>
<input class="form-control" id="id_password2" name="password2" type="password" />
</p>
</div>
<button type="submit" class="btn btn-primary" value='Submit'>Submit</button>
</form>
<p>
Already a member?
Log In Here!
</p>
{% endblock %}
Add url in your template form under action attribute as showed below:
<form role="form" method='post' action='{% url 'example' %}'>
This may fix your issues!!!.Make sure that your form has no errors.Try to add your views.py,urls.py and models.py, so we can figure it out easily.
Must be an input type not a button type use <input type="submit" class="btn btn-primary" value='Submit'>Submit</button> instead
<button type="submit" class="btn btn-primary" value='Submit'>Submit</button>

Send button is not working

I have this template:
<form role="form">
<div class="form-group">
{% bootstrap_field form.username %}
</div>
<div class="form-group">
{% bootstrap_field form.password %}
</div>
<input type="submit" value="Enviar" class="btn btn-info btn-block">
</div>
</form>
The submit button is not working what I doing bad? i've read other answers and still not working, thanks for your help!!!.
With a regular HTML form, you would need to specify a couple of attributes in <form>
You need to provide a target page where the form will be processed:
action="http://script_url_here"
You should also specify the method by which the data will be sent (either GET or POST):
method="POST"
One other thing: you had an extra </div> at the end of your form. After making those changes, your form would now look like this:
<form role="form" action="http://script_url_here" method="POST">
<div class="form-group">
{% bootstrap_field form.username %}
</div>
<div class="form-group">
{% bootstrap_field form.password %}
</div>
<input type="submit" value="Enviar" class="btn btn-info btn-block">
<!-- You had an extra </div> here -->
</form>
There are other attributes that could and ought to be specified, but they are optional.

When validating on W3C django is wrapping input fields in <tr><th>

Here is my template code for the register form
<form id="user_form" method="post" action="/accounts/register/">
{% csrf_token %}
{{ user_form }}
<br>
<input type="submit" class="btn btn-default pull-right" value="Register">
<br>
</form>
When I inspect the html of my live site or my local environment I see the following html
<form id="user_form" method="post" action="/accounts/register/">
<input type="hidden" name="csrfmiddlewaretoken" value="blah">
<label for="id_username">Username:</label><input class="form-control" id="id_username" name="username" type="text">
<label for="id_email">Email:</label><input class="form-control" id="id_email" name="email" type="email">
<label for="id_password">Password:</label><input class="form-control" id="id_password" name="password" type="password">
<br>
<input type="submit" class="btn btn-default pull-right" value="Register">
<br>
</form>
But when I validate on W3C I am getting errors because my form
Stray start tag tr. <tr><th><label for="id_username">Username:</label></th><td><inp…
And I see the markup has changed
<form id="user_form" method="post" action="/accounts/register/">
<input type='hidden' name='csrfmiddlewaretoken' value='blah' />
<tr><th><label for="id_username">Username:</label></th><td><input class="form-control" id="id_username" name="username" type="text" /></td></tr>
<tr><th><label for="id_email">Email:</label></th><td><input class="form-control" id="id_email" name="email" type="email" /></td></tr>
<tr><th><label for="id_password">Password:</label></th><td><input class="form-control" id="id_password" name="password" type="password" /></td></tr>
<br>
<input type="submit" class="btn btn-default pull-right" value="Register">
<br>
</form>
You just need to use:
{{ user_form.as_p }}
That will render the form's labels and fields inside of <p> tags. The docs give you a few options regarding output, or you can manually render the form by iterating the fields, as follows:
<!-- first output any hidden fields first -->
<div style="display: none;">
<!-- I've wrapped this in a div for W3C validation -->
{{ user_form.hidden_fields }}
</div>
{% for field in user_form.visible_fields %}
<div class="some-class">
{{ field.label_tag }}
{{ field }}
</div><!--/.some-class-->
{% endfor %}
I'd recommend giving the above a try, just to experiment with manual rendering.