I have used Django to set up the backend of a web app and have an HTML form I am using as a signup page and was wondering if there's anything I need to add to the Forms' form action attribute. What I am trying to do is grab the data that the user has posted it and send it over to PGadmin database.
Here is my html form for reference:
<div>
{% block content %}
<form action="" method="post" name="Userinfo" id="Userinfo">
<label for="fname">First Name</label>
{% csrf_token %}
<input type="text" id="fname" name="firstname" placeholder="Your first name..">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name..">
<label for="DOB">Date Of Birth</label>
<input type="text" id="DOB" name="DOB" placeholder="The Date you were born">
<label for="Email">Email Address</label>
<input type="text" id="Email" name="Email" placeholder="Your email address">
<input type="submit" value="Submit">
</form>
{% endblock %}
</div>
P.S this isn't all the whole file, just a snippet.
Also here is the views.py file that I have, which makes any imputed data get processed as a POST request vs as a GET. Not sure if there is anything I need to add in order to make it send the data to PGadmin.
class CommentForm(forms.Form):
fname = forms.CharField(max_length=25)
lname = forms.CharField(max_length=25)
dob = forms.datefield()
email = forms.EmailField()
if request.method== "POST":
form = RegisterForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
Info = form(
fname = cd['name'],
lname = cd['lname'],
dob = cd['dob'],
email = cd['email'],
)
form.save()
I have my views setup to where I have a separate app that process the backend stuff for the sign up and another that's sole purpose is to link to the right pages and links to the HTML file mentioned earlier.
Here it is, just in case
def register(request):
return render(request,"register/userinfo.html")
As usual, any help is greatly appreciated.