some fields aren't being saved in django-models - html

I am inserting new records in a model using a function-based view, but the problem is that some fields aren't being saved.
I get all fields through request.POST.get(field_name) and assign them to a variable before saving them to the corresponding field of a model.
views.py
import datetime
from django.shortcuts import render, redirect
def CreateExam(request):
if request.method == "POST":
st_exam = exam()
topic = request.POST.get("topic")
auth = request.POST.get("author")
date_now = request.POST.get("date_now")
st_exam.topic = request.POST.get("topic")
st_exam.auth = request.POST.get("author")
st_exam.date = date_now
st_exam.total_grade = request.POST.get("total_grade")
st_exam.semester_id = request.POST.get("semester")
st_exam.exam_id = auth[0:2] + topic[0:2] + date_now
# st_exam.course = request.POST.get("course")
y = datetime.now()
st_exam.semester_id = str(y.year) +'-'+request.POST.get("semester")
st_exam.save()
return redirect('/teacher/')
else:
return render(request, '500.html', {"error": "Ooops Illegal access"})
models.py
from django.db import models
class exam(models.Model):
exam_id = models.CharField(max_length=40,null=True)
date = models.CharField(max_length=40,null=True)
total_grade = models.FloatField(null=True)
author= models.CharField(max_length=40,null=True)
topic = models.CharField(max_length=40,null=True)
course = models.CharField(max_length=40,null=True)
semester_id = models.CharField(max_length=40,null=True)
template.html
<form method="post" action="/teacher/create/exam/">
{% csrf_token %}
<div class="form-group col-md-8">
<label for="topic">Topic</label>
<input type="text" name="topic" class="form-control" id="topic"/>
</div>
<div class="form-group col-md-8">
<label for="grade">Author</label>
<input type="text" name="author" class="form-control" id="author"/>
</div>
<div class="form-group col-md-8">
<label for="date">Date</label>
<input type="date" name="date_now" class="form-control" id="date"/>
</div>
<div class="form-group col-md-8">
<label for="grade">Course</label>
<input type="text" name="course" class="form-control" id="grade"/>
</div>
<div class="form-group col-md-8">
<label for="grade">grade</label>
<input type="number" name="total_grade" class="form-control" id="grade"/>
</div>
<div class="form-group col-md-8">
<label for="cat">Semester </label>
<select name="semester" class="form-control">
<option value="1"> Semester 1</option>
<option value="2"> Semester 2</option>
</select>
</div>
<button type="submit"
class="btn btn-primary m-t-15 waves-effect">Save
</button>
</form>
I expect all fields to be saved but the author field doesn't get saved

Related

Register data by multiple select django

I'm a beginner and I was trying to create a registered data form in the database, all the fields are registered well instead of the multiple select fields.
from.py
class SavePost(forms.ModelForm):
user = forms.IntegerField(help_text = "User Field is required.")
title = forms.CharField(max_length=250,help_text = "Title Field is required.")
description = forms.Textarea()
dep = forms.Textarea()
class Meta:
model= Post
fields = ('user','title','description','file_path', 'file_path2', 'dep')
HTML
<div class="form-group mb-3 ">
<label for="exampleFormControlSelect2"> multiple select</label>
<select multiple class="form-control" id="dep" value={{ post.title }}>
<option>Process</option>
<option>Product</option>
<option>Equipment</option>
</select>
</div>
<div class="form-group mb-3 ">
<label for="title" class="control-label">Title</label>
<input type="text" class="form-control rounded-0" id="title" name="title" value="{{ post.title }}" required>
</div>
<div class="form-group mb-3">
<label for="description" class="control-label">Description</label>
<textarea class="form-control rounded-0" name="description" id="description" rows="5" required>{{ post.description }}</textarea>
thank you in advanced
You need a ChoiceField, write it as follows,
class SavePost(forms.ModelForm):
CHOICES = [('Process', 'Process'), ('Product', 'Product'),
('Equipment', 'Equipment')]
dep = forms.ChoiceField(choices=CHOICES)
user = forms.IntegerField(help_text = "User Field is required.")
title = forms.CharField(max_length=250,help_text = "Title Field is required.")
description = forms.Textarea()
class Meta:
model= Post
fields = ('user','title','description','file_path', 'file_path2', 'dep')
Check out the Django docs
You won't need to build the select in the template. I figure you are calling the for "post" from the view.py. So you will just need to create field in template with {{post.dep}}.

checking radio button on Django view from template

I am creating a custom sign up form and this is the view I created:
def signup(request):
if request.user.is_authenticated:
return render(request, 'listings/index.html', {})
if request.method == 'POST':
if 'cr-1' in request.POST:
newuser = User.objects.create_user(username=request.POST.get('email'), email=request.POST.get('email'), password=request.POST.get('password'))
newpatient = Patient.objects.create(user=newuser)
user = authenticate(request, username=username, password=password)
if user is not None:
auth_login(request, user)
return redirect('dashboard')
elif 'cr-2' in request.POST:
newuser = User.objects.create_user(username=request.POST.get('email'), email=request.POST.get('email'), password=request.POST.get('password'))
newdoctor = Doctor.objects.create(user=newuser)
user = authenticate(request, username=username, password=password)
if user is not None:
auth_login(request, user)
return redirect('dashboard')
else:
print("##################### NOTHING HAPPENED #####################")
return render(request, 'dashboard/signup.html', {})
I purposely added an else statement printing NOTHING HAPPENED on the console because nothing happens when I click on submit.
Here is the template:
<form class="form-type-material" method="POST" action="{% url 'signup' %}">
{% csrf_token %}
<div class="custom-control custom-radio">
<input type="radio" id="cr-1" name="rg-1" class="custom-control-input" checked>
<label class="custom-control-label" for="cr-1">Patient/Visiteur</label>
</div>
<div class="custom-control custom-radio">
<input type="radio" id="cr-2" name="rg-1" class="custom-control-input">
<label class="custom-control-label" for="cr-2">Médecin/Praticien</label>
</div>
<div class="form-group">
<input type="text" class="form-control" id="id_email" name="email" required>
<label for="email">Adresse email</label>
</div>
<div class="form-group">
<input type="password" class="form-control" id="id_password" name="password" required>
<label for="password">Mot de passe</label>
</div>
<div class="form-group">
<input type="password" class="form-control" id="id_password-conf" name="password-conf" required>
<label for="password-conf">Confirmation du mot de passe</label>
</div>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" required>
<label class="custom-control-label">I agree to all <a class="text-primary" href="#">terms</a></label>
</div>
</div>
<br>
<button class="btn btn-bold btn-block btn-primary" type="submit">Créer et accéder au tableau de bord</button>
</form>
What seems to be the issue?
PS: In a previous attempt I did if 'cr-1'.checked in request.POST because I saw it in another stackoverflow thread but it gave me the error: str .... has no checked method.
Here in your template you have 'cr-1' and 'cr-2' as ids, but while submitting the form the name will be sent. i.e here you have name name="rg-1"
So, you need to check
if 'rg-1' in request.POST:

How to sed data from database to html form in Flask for editing

I am trying to send the data from the database to the Html form, but I'm getting an error like this
TypeError: 'ImmutableMultiDict' objects are immutable
this is the flask code for editing the data
#app.route('/edit-project/<string:id>', methods = ['GET', 'POST'])
def edit_project(id):
project = Project.query.get(id)
request.form['title'] = project.title
request.form['link'] = project.link
request.form['description'] = project.description
if request.method == 'POST':
title = request.form['title']
link = request.form['link']
description = request.form['description']
image = request.files['image']
image.save(os.path.join(app.config["IMAGE_UPLOADS"], 'project/'+ project.image))
return render_template('project/edit_project.html')
The Html template 'edit_project.html' is shown below
<div class="container">
<form method="POST" id="project-form" enctype="multipart/form-data">
<div class="form-group">
<input type="text" name="title" class="form-control" id="title" placeholder="Title">
</div>
<div class="form-group">
<input type="text" name="link" class="form-control" id="title" placeholder="Project Link">
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Description</label>
<textarea id = project-form name="description" class="form-control" id="description" rows="3"></textarea>
</div>
<div class="input-group" style="width: 30%;">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
</div>
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
<label class="custom-file-label" for="inputGroupFile01">Upload image</label>
</div>
</div>
<div class="form-group" style="padding-top: 2rem;">
<button type="submit" class="btn btn-primary">Publish</button>
</div>
</form>
</div>
Is there is any way to display the data in the form without using WTForms or do I've to use WTForms instead?
Thanks in advance.
Can you use jinja templating?
render_template() takes data argument. You can pass the data from your DB to that call and use jinja templates in HTML to render it. Setting the values of your input will do.
For example:
Your data is data = {title:"apple"}
And, return render_template("project/edit_project.html", data=data) will provide you data object in HTML file.
There, you can use jinja like this:
<div class="form-group">
<input type="text" name="title" class="form-control" id="title" placeholder="Title" value={{data.text}}>
</div>
Hope it helps!

How to resolve value error in my views file

Can anyone please help me solve this problem in my view. I have been stuck for quite a time now. Any help will be highly appreciated.
My Error
System check identified no issues (0 silenced).
December 18, 2019 - 09:28:36
Django version 2.2.8, using settings 'Timesheet.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[18/Dec/2019 09:28:42] "GET / HTTP/1.1" 200 6027
Internal Server Error: /
Traceback (most recent call last):
File "D:\Django\TimeSheetProject\morabu\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "D:\Django\TimeSheetProject\morabu\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
"returned None instead." % (callback.__module__, view_name)
ValueError: The view morabu_timesheet.views.create_timesheet_view didn't return an HttpResponse object. It returned None instead.
[18/Dec/2019 09:29:02] "POST / HTTP/1.1" 500 65059
My views.py
And I don't know whether my method is correct or not but I want to save the data from the raw HTML form only since I have to do some front end validation using java script.
from django.shortcuts import render
from .models import TimesheetDetails
# Create your views here.
def create_timesheet_view(request):
if request.method=="POST":
if(request.POST.get('dateToday') and request.POST.get('dayToday') and request.POST.get('startTime')
and request.POST.get('endTime')and request.POST.get('breakTime')and request.POST.get('normalTime')
and request.POST.get('overTime')and request.POST.get('holidayTime')and request.POST.get('weekType')
and request.POST.get('attendance')and request.POST.get('content')):
post = TimesheetDetails()
post.date = request.POST.get('dateToday')
post.day = request.POST.get('day_today')
post.startTime = request.POST.get('startTime')
post.endTime = request.POST.get('endTime')
post.breakTime = request.POST.get('breakTime')
post.normalTime = request.POST.get('normalTime')
post.overTime = request.POST.get('overTime')
post.holidayTime = request.POST.get('holidayTime')
post.weekType = request.POST.get('weekType')
post.attendance = request.POST.get('attendance')
post.content = request.POST.get('content')
if post.is_valid():
try:
post.save()
return render(request,'timesheet/view_timesheet.html')
except :
pass
else:
return render(request,'timesheet/create_timesheet.html')
def view_timesheet(request):
return render(request,"timesheet/view_timesheet.html")
my models.py
class TimesheetDetails(models.Model):
date = models.CharField(max_length = 10)
day = models.CharField(max_length = 10)
startTime = models.CharField(max_length =10)
endTime = models.CharField(max_length =10)
breakTime = models.CharField(max_length=3)
normalTime = models.CharField(max_length=10)
overTime = models.CharField(max_length = 10)
holidayTime = models.CharField(max_length = 10)
weekType = models.CharField( max_length = 10)
attendance = models.CharField( max_length = 10)
content = models.TextField( max_length = 300)
And Lastly my HTML page
<form action="" method="post" autocomplete="off">
{% csrf_token %}
<h3 id="date_Today"></h3>
<p id="dayToday" name="dayToday" class="hideMe"></p>
<p id="dateToday" name="dateToday" class="hideMe"></p>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="startTime">開始時間</label>
<input type="text" class="form-control" name="startTime" id="startTime" placeholder="(HH:mm)フォーマットに入力して下さい">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="endTime">終業時間</label>
<input type="text" class="form-control" name="endTime" id="endTime" placeholder="(HH:mm)フォーマットに入力して下さい">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="breakTime">休憩時間</label>
<input type="text" class="form-control" name="breakTime" id="breakTime" >
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="normalTime">時間内時間</label>
<input type="text" class="form-control" name="breakTime" id="normalTime" >
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="extraTime">時間外時間</label>
<input type="text" class="form-control" name="extraTime" id="extraTime">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="holidayTime">休日時間</label>
<input type="text" class="form-control" name="holidayTime" id="holidayTime" >
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="weekType">区分は間違えないでしょうか?</label>
<select class="form-control" name="weekType" id="weekType">
<option value="平日">平日</option>
<option value="休日">休日</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="reason">勤怠を選んでください!</label>
<select class="form-control" name="attendance" id="attendance">
<option value="欠勤">欠勤</option>
<option value="有給休暇">有給休暇</option>
<option value="振替休日">振替休日</option>
<option value="特別休暇">特別休暇</option>
<option value="残業">残業</option>
<option value="早退">早退</option>
<option value="遅刻">遅刻</option>
<option value="直行">直行</option>
<option value="直帰">直帰</option>
<option value="その他">その他</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="workContent">恐れ入りますが、仕事の内容を書いていただきませんでしょうか?</label>
<textarea class="form-control" name="workContent" id="workContent" rows="3"></textarea>
</div>
</div>
</div>
</div>
<button type="submit" class="btn btn-success btn-block"><i class="fas fa-database"></i> 保存</button>
</form>
Welcome to SO :)
You're not returning a HttpResponse when post.is_valid() returns False.
from django.shortcuts import render
from .models import TimesheetDetails
# Create your views here.
def create_timesheet_view(request):
if request.method=="POST":
if(request.POST.get('dateToday') and request.POST.get('dayToday') and request.POST.get('startTime')
and request.POST.get('endTime')and request.POST.get('breakTime')and request.POST.get('normalTime')
and request.POST.get('overTime')and request.POST.get('holidayTime')and request.POST.get('weekType')
and request.POST.get('attendance')and request.POST.get('content')):
post = TimesheetDetails()
post.date = request.POST.get('dateToday')
post.day = request.POST.get('day_today')
post.startTime = request.POST.get('startTime')
post.endTime = request.POST.get('endTime')
post.breakTime = request.POST.get('breakTime')
post.normalTime = request.POST.get('normalTime')
post.overTime = request.POST.get('overTime')
post.holidayTime = request.POST.get('holidayTime')
post.weekType = request.POST.get('weekType')
post.attendance = request.POST.get('attendance')
post.content = request.POST.get('content')
if post.is_valid():
try:
post.save()
return render(request,'timesheet/view_timesheet.html')
except :
pass
else:
return render(request,'timesheet/create_timesheet.html') #Adding this line
else:
return render(request,'timesheet/create_timesheet.html')
def view_timesheet(request):
return render(request,"timesheet/view_timesheet.html")

Required attribute set but no validation

i have a bootstrap site and have 4 different forms. I set the required attribute against certain fields. On my local machine, the validation works if the fields are left blank but when I post it to a web host, the validation does not work.
The field types range from free text input to check boxes, select boxes and radio buttons.
I am writing this from my mobile so don't have a snippet of code to show. Sorry all. Suggestions are more than welcome.
<fieldset>
<b><u><h4>Trip Type</h4></u></b>
<div class = "form-group">
<label for="where">Will you be:</label>
<select class="form-control" id="where" name = "where" required>
<option></option>
<option value = "travelling to">Travelling to the Airport</option>
<option value = "travelling from">Travelling from the Airport</option>
</select>
</div>
<div class = "row">
<div class = "col-lg-6 col-md-6">
<div class = "form-group">
<label for = "airporttype">From / to which airport:</label>
<div class = "radio">
<label class="radio-inline"><input type="radio" name="airporttype" id = "airporttype" value = "International" required>International</label>
<label class="radio-inline"><input type="radio" name="airporttype" id = "airporttype" value = "Domestic">Domestic</label>
</div>
</div>
</div>
<div class = "col-lg-6 col-md-6">
<div class="control-group form-group">
<label for = "trip">Is this a Single or Return Trip:</label>
<div class = "radio">
<label class="radio-inline"><input type = "radio" name = "trip" id = "trip" class = "return" value = "Single" required>Single</label>
<label class="radio-inline"><input type = "radio" name = "trip" id = "trip" class = "return" value = "Return">Return Trip</label>
</div>
</div>
</div>
</div>
<hr>
<b><u><h4>Your Details</h4></u></b>
<div class="control-group form-group">
<div class="controls">
<label for = "fname">First Name:</label>
<input type = "text" class = "form-control" id = "fname" name = "fname" required placeholder = "Enter First Name" data-validation-required-message="Please enter your first name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label for = "surname">Last Name:</label>
<input type="text" class="form-control" id="surname" name = "surname" required placeholder = "Enter Last Name" data-validation-required-message="Please enter your last name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label for = "cell1">Contact Mobile / Cell:</label>
<input type="text" class="form-control" id="cell1" name = "cell1" required placeholder = "Enter Mobile / Cell Number Main" data-validation-required-message="Please enter your main contact number.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label for = "cell2">Contact Mobile / Cell 2:</label>
<input type="text" class="form-control" id="cell2" name = "cell2" placeholder = "Enter Mobile / Cell Number Alt" data-validation-required-message="Please enter your alternate contact number.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label for = "email">Enter your email address:</label>
<input type = "email" class = "form-control" id = "email" name = "email" required placeholder = "you#yourdomain.com" data-validation-required-message="Please enter your email address.">
<p class="help-block"></p>
</div>
</div>
<br>
<div class="control-group form-group">
<div class="controls">
<label for = "date16">Travel Date:</label>
<input type = "text" class="form-control datepicker" id = "date16" name = "date16" required data-validation-required-message="Please enter your travel date." style = "text-align: center">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label for="address">Pick Up / Destination Address:</label>
<input type = "text" class = "form-control" id = "address" name = "address" placeholder = "The start or end of your journey" required data-validation-required-message = "Please enter the address where you will start or finish your journey.">
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label for = "passnum">Number of Passengers:</label>
<select class="form-control" id = "passnum" name = "passnum" required>
<option></option>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
<option value = "4">4</option>
<option value = "5">5</option>
<option value = "6">6</option>
<option value = "7">7</option>
<option value = "8">8</option>
<option value = "9">9</option>
<option value = "10">10</option>
<option value = "11">11</option>
<option value = "12">12</option>
<option value = "13">13</option>
<option value = "14">14</option>
<option value = "15">15</option>
<option value = "16">16</option>
<option value = "17">17</option>
<option value = "18">18</option>
<option value = "19">19</option>
<option value = "20">20</option>
<option value = "21">21</option>
<option value = "22">22</option>
<option value = "23">23</option>
<option value = "24">24</option>
</select>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label for = "flightnum">Flight Number:</label>
<input type = "text" class="form-control" id = "flightnum" name = "flightnum" placeholder = "Please enter your flight number" required data-validation-required-message = "Please enter your flight number.">
<p class="help-block"></p>
</div>
</div>
<hr>
<b><u><h4>Child Seats</h4></u></b>
<div class = "row">
<div class = "col-lg-4">
<div class="control-group form-group">
<label for = "babyseat">Baby Seat Required:</label>
<div class = "radio">
<label class="radio-inline"><input type = "radio" name = "babyseat" id = "babyseat" class = "bseat12" value = "Yes" required>Yes</label>
<label class="radio-inline"><input type = "radio" name = "babyseat" id = "babyseat" class = "bseat12" value = "No">No</label>
</div>
</div>
<div class="control-group form-group" id = "babyseat1">
<div class="controls">
<label for = "bseatnum">Number of Baby Seats:</label>
<select class="form-control" id = "bseatnum" name = "bseatnum">
<option></option>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
<option value = "4">4</option>
<option value = "5">5</option>
</select>
</div>
</div>
</div>
<div class = "col-lg-4">
<div class="control-group form-group">
<label for = "boost">Booster Seat Required:</label>
<div class = "radio">
<label class="radio-inline"><input type = "radio" name = "boost" id = "boost" class = "boost12" value = "Yes" required>Yes</label>
<label class="radio-inline"><input type = "radio" name = "boost" id = "boost" class = "boost12" value = "No">No</label>
</div>
</div>
<div class="control-group form-group" id = "boost1" >
<div class="controls">
<label for = "boostnum">Number of Booster Seats:</label>
<select class="form-control" id = "boostnum" name = "boostnum">
<option></option>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
<option value = "4">4</option>
<option value = "5">5</option>
</select>
</div>
</div>
</div>
<div class = "col-lg-4">
<div class="control-group form-group">
<label for = "cradle">Baby Cradle Required</label>
<div class = "radio">
<label class="radio-inline"><input type = "radio" name = "cradle" id = "cradle" class = "cradle12" value = "Yes" required>Yes</label>
<label class="radio-inline"><input type = "radio" name = "cradle" id = "cradle" class = "cradle12" value = "No">No</label>
</div>
</div>
<div class="control-group form-group" id = "cradle1">
<div class="controls">
<label for = "cradlenum">Number of cradles:</label>
<select class="form-control" id = "cradlenum" name = "cradlenum">
<option></option>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
<option value = "4">4</option>
<option value = "5">5</option>
</select>
</div>
</div>
</div>
</div>
<hr>
<b><u><h4>Additional Services</h4></u></b>
<div class = "row">
<div class = "col-lg-6">
<div class="control-group form-group">
<label for = "shuttle">Shuttle Service:</label>
<div class="radio">
<label for = "shuttle" class="radio-inline"><input id = "shuttle" name = "shuttle" type="radio" value = "Yes" required>Yes</label>
<label for = "shuttle" class="radio-inline"><input id = "shuttle" name = "shuttle" type="radio" value = "No">No</label>
<p class="help-block"></p>
</div>
</div>
</div>
<div class = "col-lg-6">
<div class="control-group form-group">
<label for "charter">Private Charter:</label>
<div class="radio">
<label class="radio-inline"><input type="radio" name="charter" id = "charter" value = "Yes" required>Yes</label>
<label class="radio-inline"><input type="radio" name="charter" id = "charter" value = "No">No</label>
<p class="help-block"></p>
</div>
</div>
</div>
</div>
<hr>
</fieldset>
validation only using required attribute is not good, because it may not work in many cases. for example when using javascript submit() method, also in some browsers,required wont work. So Best way is to validate using javascript(client side)
So create a javascript function and call it during form onsubmit event
function checkform(form) {
var inputs = form.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if(inputs[i].hasAttribute("required")){
if(inputs[i].value == ""){
alert("Please fill all required fields");
return false;
}
}
}
return true;
}