I have html form
with some text input for a users registration, the form is like this:
<form id="signup-form" action="#" method="post">
<label for="name">Full Name</label>
<input autocomplete="off" type="text" name="username" id="name" class="name">
<label for="email">Email Adderss</label>
<input autocomplete="off" type="email" name="emailAdress" id="email" class="email">
<label for="phone">Phone Number - <small>Optional</small></label>
<input autocomplete="off" type="text" name="phone" id="phone">
<label for="password">Password</label>
<input autocomplete="off" type="password" name="password" id="password" class="pass">
<label for="passwordCon">Confirm Password</label>
<input type="password" name="passwordCon" id="passwordCon" class="passConfirm">
<input type="submit" form="signup-form" value="Signup Now" id="submit">
</form>
I want to know, how can i store the values of each input, when the button is submitted and save them in the database, is there a way to call the input field by its ID and store it in Django?
Your code template is missing a lot of things like urls , views and models . What views you are working with , url of the form submission , and what database. But here is a simple structure of the form submission if you are using django user model and not using custom model .
You have your form template. It works fine , but add a new field after tag for csrf_verification of the template.
<form>
{% csrf_token %}
...
...
</form>
Your urls.py for the signup
from django.urls import path
from . import views
urlpatterns = [
path("signup/" , views.signUpView , name = "user-signup") ,
]
Your views.py I am using a function-based view here and django User model.
from django.contrib.auth.models import User
from django.contrib.auth import login
def signUpView(request , *args , **kwargs):
if request.method == "POST":
username = request.POST.get("username")
emailAddress = request.POST.get("emailAddress")
password = request.POST.get("password")
# get all your fields which you gave in the form.
user = User(userrname = username , email = emailAddress )
user.set_password(password)
user.save()
login(request , user)
return redirect("homepage")
else :
return render(request , "signupPage.html")
This is your basic template and working of django signup page. And this will do your work which you are asking for. For detailed and specific answer. Elaborate the question.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments