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;
}
Related
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")
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
I have setup a codepen so you can see what I want. Click here to open the codepen: https://codepen.io/tbellmer/pen/RdxBdQ
I am relatively new at this and while the form is functional, I need help with the aesthetics. I would like to have both the Action: and Comment: labels be right aligned. I am trying to use the most modern techniques so not looking to use a table or float.
My code uses a flexbox to have an aside section and main section. Can I use a flexbox or grid to do what I want? Also notice that I used a for some vertical spacing and suspect there is a better way to do this as well.
Your assistance will be greatly appreciated!
<div class="container">
<div class="flex-grid">
<aside class="col sidebar">
<p class = 'ctr'>Welcome</p>
</aside>
<section class="col main">
<h1 class='ctr'>Title</h1>
<hr>
<form action = '#'>
<label for = 'combo'>Action: </label>
<select id = 'combo' name = 'response' required>
<option value = ''>--none--</option>
<option value = 'A'>Approved</option>
<option value = 'R'>Rejected</option>
</select>
<p></p> <!-- has to be a better way to get space -->
<!-- want to have both Action: and Comment: labels line up to right -->
<label for = 'comment'>Comment: <label>
<input type=text id='comment' size='40' name='comment'>
<p></p>
<input class = 'button' type = 'submit' value = 'Submit' id = 'submit'>
<input class = 'button' type = 'reset' value = 'Cancel'>
</form>
</section>
</div>
</div>
You can create a div inside the form tag just like i did below and add a class with the
CSS
.display-align {
display: grid;
grid-template-columns: max-content max-content;
grid-gap:5px;
}
HTML
<form>
<div class="display-align">
<div>
<label for = 'combo'>Action: </label>
<br><br>
<label for = 'comment'>Comment: <label>
</div>
<div>
<select id = 'combo' name = 'response' required">
<option value = ''>--none--</option>
<option value = 'A'>Approved</option>
<option value = 'R'>Rejected</option>
</select>
<br><br>
<input type=text id='comment' size='40' name='comment'>
</div>
</div>
<br>
<div>
<input class = 'button' type = 'submit' value = 'Submit' id = 'submit'>
<input class = 'button' type = 'reset' value = 'Cancel'>
</div>
</form>
You can use the <br> tag to break a line or still use the <p> .
But may I suggest to you use this instead(its basically the same, but different lol).
I use the same CSS class in this code.
<form>
<fieldset style="max-width: 400px;">
<legend>Title</legend>
<div class="display-align">
<div>
<label for = 'combo'>Action: </label>
<br><br>
<label for = 'comment'>Comment: <label>
</div>
<div>
<select id = 'combo' name = 'response' required">
<option value = ''>--none--</option>
<option value = 'A'>Approved</option>
<option value = 'R'>Rejected</option>
</select>
<br><br>
<input type=text id='comment' size='40' name='comment'>
</div>
</div>
<br>
<div>
<input class = 'button' type = 'submit' value = 'Submit' id = 'submit'>
<input class = 'button' type = 'reset' value = 'Cancel'>
</div>
</fieldset>
</form>
I'm making a form for a task in class and nobody can figure out why the input validation isn't working. The code for the whole form is below. It's specifically the required tag that seems to be causing problems.
<form action = "">
<p>First Name</p>
<input type = "text" name = "firstname" size = "25" maxlength = "20"></input> <br>
<p>Last Name</p>
<input type = "text" name = "lastname" size = "25" maxlength = "20"></input> <br>
<p>Age</p>
<input type = "radio" name = "age" value = "<25" checked></input><25
<input type = "radio" name = "age" value = "25-40" ></input>25-40
<input type = "radio" name = "age" value = ">40" ></input>>40
<input type = "radio" name = "age" value = "Rather not say" ></input>Rather not say <br>
<div style = "float:left">
<p>Favourite food</p>
<select name = "Favourite food" style = "float:left;">
<option value = "1" selected>Italian</option>
<option value = "2">Indian</option>
<option value = "3">Thai</option>
<option value = "4">Chinese</option>
</select>
</div>
<br>
<div style = "float:right">
<p>What new country would you like to see on the website?</p>
<select name = "newCountry">
<option value = "1" selected>Vietnamese</option>
<option value = "2">American</option>
<option value = "3">French</option>
<option value = "4">Spanish</option>
</select>
</div>
<br>
<p style = "clear:both; float:left;">What new cooking technique would you like to see on the website?</p>
<textarea name = "NewTechnique" rows = "5" cols = "100" maxlength = "500" style = "clear:both;"> </textarea>
<br>
<p>Please rate the following from 1 (poor) to 5 (excellent)</p>
<p>Ease of use</p>
<input type = "text" name = "easeofuse" size = "25" min = "1" max = "5" required=""></input> <br>
<p>Quality of information</p>
<input type = "text" name = "infoquality" size = "25" min = "1" max = "5" required></input> <br>
<p>Taste of recipies</p>
<input type = "text" name = "tastes" size = "25" min = "1" max = "5" required = ""></input> <br>
<p>Permission for my information to be held and used for future developments</p>
<input type ="radio" name = "permission" value = "1" required></input>Yes
<input type ="radio" name = "permission" value = "2"></input>No
<input type = "submit" onclick="alert('form entered')" value = "submit"></input>
</form>
I can't see what the problem is. Is it because the action tag is empty? We've been told to leave it like that.
Edit:Problem has been solved!
To get the form required fields to work, I've replaced the onclick with onsubmit inside the form tag. I've also cleaned up whatever HTML oddities I found after a quick skim (I've probably missed a few).
<form onsubmit='alert("ya done clicked")'>
<p>First Name</p>
<input type="text" name="firstname" size="25" maxlength="20"> <br>
<p>Last Name</p>
<input type="text" name="lastname" size="25" maxlength="20"> <br>
<p>Age</p>
<input type="radio" name="age" value="<25" checked><25
<input type="radio" name="age" value="25-40">25-40
<input type="radio" name="age" value=">40">>40
<input type="radio" name="age" value="Rather not say">Rather not say <br>
<div style="float:left">
<p>Favourite food</p>
<select name="Favourite food" style="float:left;">
<option value="1" selected>Italian</option>
<option value="2">Indian</option>
<option value="3">Thai</option>
<option value="4">Chinese</option>
</select>
</div>
<br>
<div style="float:right">
<p>What new country would you like to see on the website?</p>
<select name="newCountry">
<option value="1" selected>Vietnamese</option>
<option value="2">American</option>
<option value="3">French</option>
<option value="4">Spanish</option>
</select>
</div>
<br>
<p style="clear:both; float:left;">What new cooking technique would you like to see on the website?</p>
<textarea name="NewTechnique" rows="5" cols="100" maxlength="500" style="clear:both;"> </textarea>
<br>
<p>Please rate the following from 1 (poor) to 5 (excellent)</p>
<p>Ease of use</p>
<input type="text" name="easeofuse" size="25" min="1" max="5" required> <br>
<p>Quality of information</p>
<input type="text" name="infoquality" size="25" min="1" max="5" required> <br>
<p>Taste of recipies</p>
<input type="text" name="tastes" size="25" min="1" max="5" required> <br>
<p>Permission for my information to be held and used for future developments</p>
<input type="radio" name="permission" value="1" required>Yes
<input type="radio" name="permission" value="2">No
<input type="submit" value="submit">
</form>
I have a form in Bootstrap 3 that's inside a modal. There's a button called "submit" where when it's clicked the stuff that was entered in the form should be sent to the database. Although when I click "Submit" nothing happens.
Here is a live preview: http://rentmycar.pe.hu/index.html
<!--Checkout Modal Start -->
<div class = "modal fade" id = "checkoutModal" tabindex = "-1" role = "dialog" aria-labelledby = "checkoutModalLabel" aria-hidden = "true" data-backdrop = "static">
<div class = "modal-dialog">
<div class = "modal-content">
<form action = "index.html" method = "post" id = "checkout-form" name = "checkout-form">
<!--Modal header start -->
<div class = "modal-header">
<button type = "button" class = "close" data-dismiss = "modal" aria-hidden = "true">×
</button>
<h4 class = "modal-title" id = "myModalLabel">Complete reservation</h4>
</div>
<!--Modal header end -->
<!--Modal body start -->
<div class = "modal-body">
<!--Checkout Info start -->
<div class = "checkout-info-box">
<h3><i class = "fa fa-info-circle"></i> Upon completing this reservation enquiry, you will receive::</h3>
<p>Your rental voucher to produce on arrival at the rental desk and a toll-free customer support number.</p>
</div>
<!--Checkout Info end -->
<!--Checkout Rental Info start -->
<div class = "checkout-vehicle-info">
<div class = "location-date-info">
<h3>Location & Date</h3>
<div class = "info-box">
<span class = "glyphicon glyphicon-calendar"></span>
<h4 class = "info-box-title">Pick-Up Time</h4>
<p class = "info-box-description"><span id = "pick-up-date-ph"></span> at <span id = "pick-up-time-ph"></span></p>
<input type = "hidden" name = "pick-up" id = "pick-up" value = "">
</div>
<div class = "info-box">
<span class = "glyphicon glyphicon-calendar"></span>
<h4 class = "info-box-title">Drop-Off Time</h4>
<p class = "info-box-description"><span id = "drop-off-date-ph"></span> at <span id = "drop-off-time-ph"></span></p>
<input type = "hidden" name = "drop-off" id = "drop-off" value = "">
</div>
<div class = "info-box">
<span class = "glyphicon glyphicon-map-marker"></span>
<h4 class = "info-box-title">Pick-Up Location</h4>
<p class = "info-box-description" id = "pickup-location-ph"></p>
<input type = "hidden" name = "pickup-location" id = "pickup-location" value = "">
</div>
<div class = "info-box">
<span class = "glyphicon glyphicon-map-marker"></span>
<h4 class = "info-box-title">Drop-Off Location</h4>
<p class = "info-box-description" id = "dropoff-location-ph"></p>
<input type = "hidden" name = "dropoff-location" id = "dropoff-location" value = "">
</div>
</div>
<div class = "vehicle-info">
<h3>CAR: <span id = "selected-car-ph"></span></h3> [Vehicle Models]
<input type = "hidden" name = "selected-car" id = "selected-car" value = "">
<div class = "clearfix"></div>
<div class = "vehicle-image">
<img class = "img-responsive" id = "selected-vehicle-image" src = "#" alt = "Vehicle">
</div>
</div>
<div class = "clearfix"></div>
</div>
<!--Checkout Rental Info end -->
<hr>
<!--Checkout Personal Info start -->
<div class = "checkout-personal-info">
<div class = "alert hidden" id = "checkout-form-msg">
test
</div>
<h3>PERSONAL INFORMATION</h3>
<div class = "form-group left">
<label for = "first-name">First Name:</label>
<input type = "text" class = "form-control" name = "first-name" id = "first-name" placeholder = "Enter your first name">
</div>
<div class = "form-group right">
<label for = "last-name">Last Name:</label>
<input type = "text" class = "form-control" name = "last-name" id = "last-name" placeholder = "Enter your last name">
</div>
<div class = "form-group left">
<label for = "phone-number">Phone Number:</label>
<input type = "text" class = "form-control" name = "phone-number" id = "phone-number" placeholder = "Enter your phone number">
</div>
<div class = "form-group right age">
<label for = "age">Age:</label>
<div class = "styled-select-age">
<select name = "age" id = "age">
<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>
<option value = "25">25</option>
<option value = "26">26</option>
<option value = "27">27</option>
<option value = "28">28</option>
<option value = "29">29</option>
<option value = "30">30</option>
<option value = "31">31</option>
<option value = "32">32</option>
<option value = "33">33</option>
<option value = "34">34</option>
<option value = "35">35</option>
<option value = "36">36</option>
<option value = "37">37</option>
<option value = "38">38</option>
<option value = "39">39</option>
<option value = "40">40</option>
<option value = "41">41</option>
<option value = "42">42</option>
<option value = "43">43</option>
<option value = "44">44</option>
<option value = "45">45</option>
<option value = "46">46</option>
<option value = "47">47</option>
<option value = "48">48</option>
<option value = "49">49</option>
<option value = "50">50</option>
<option value = "51">51</option>
<option value = "52">52</option>
<option value = "53">53</option>
<option value = "54">54</option>
<option value = "55">55</option>
<option value = "56">56</option>
<option value = "57">57</option>
<option value = "58">58</option>
<option value = "59">59</option>
<option value = "50">50</option>
<option value = "61">61</option>
<option value = "62">62</option>
<option value = "63">63</option>
<option value = "64">64</option>
<option value = "65">65</option>
<option value = "66">66</option>
<option value = "67">67</option>
<option value = "68">68</option>
<option value = "69">69</option>
<option value = "70">70</option>
<option value = "71">71</option>
<option value = "72">72</option>
<option value = "73">73</option>
<option value = "74">74</option>
<option value = "75">75</option>
<option value = "76">76</option>
<option value = "77">77</option>
<option value = "78">78</option>
<option value = "79">79</option>
<option value = "80">80</option>
<option value = "81">81</option>
<option value = "82">82</option>
<option value = "83">83</option>
<option value = "84">84</option>
<option value = "85">85</option>
<option value = "86">86</option>
<option value = "87">87</option>
<option value = "88">88</option>
<option value = "89">89</option>
<option value = "90">90</option>
<option value = "91">91</option>
<option value = "92">92</option>
<option value = "93">93</option>
<option value = "94">94</option>
<option value = "95">95</option>
<option value = "96">96</option>
<option value = "97">97</option>
<option value = "98">98</option>
<option value = "99">99</option>
<option value = "100">100</option>
</select>
</div>
</div>
<div class = "form-group left">
<label for = "email-address">Email:</label>
<input type = "email" class = "form-control" name = "email-address" id = "email-address" placeholder = "Enter your email address">
</div>
<div class = "form-group right">
<label for = "email-address-confirm">Confirm Email Address:</label>
<input type = "email" class = "form-control" name = "email-address-confirm" id = "email-address-confirm" placeholder = "Confirm your email address">
</div>
<div class = "clearfix"></div>
</div>
<!--Checkout Personal Info end -->
<!--Checkout Address Info start -->
<div class = "checkout-address-info">
<div class = "form-group address">
<label for = "address">Address</label>
<input type = "text" class = "form-control" name = "address" id = "address" placeholder = "Enter your Street an No.">
</div>
<div class = "form-group city">
<label for = "city">City</label>
<input type = "text" class = "form-control" name = "city" id = "city" placeholder = "Enter your City">
</div>
<div class = "form-group zip-code">
<label for = "zip-code">Zip Code</label>
<input type = "text" class = "form-control" name = "zip-code" id = "zip-code" placeholder = "Enter your Zip Code">
</div>
<div class = "clearfix"></div>
</div>
<!--Checkout Address Info end -->
<div class = "newsletter">
<div class = "form-group">
<div class = "checkbox">
<input id = "check1" type = "checkbox" name = "newsletter" value = "yes">
<label for = "check1">Please send me latest news and updates</label>
</div>
</div>
</div>
</div>
<!--Modal body end -->
<!--Modal footer start -->
<div class = "modal-footer">
<span class = "btn-border btn-gray">
<button type = "button" class = "btn btn-default btn-gray" data-dismiss = "modal">Cancel</button>
</span>
<span class = "btn-border btn-yellow">
<button type="submit" class="btn btn-primary btn-yellow">Reserve now</button>
</span>
</div>
<!--Modal footer end -->
</form>
</div>
</div>
</div>
<!--Checkout Modal end -->
You can change this
<button type="submit" class="btn btn-primary btn-yellow">Reserve now</button>
to
<input type="submit" class="btn btn-primary btn-yellow" value="Reserve now">
Change the href from #teaser to something:
<span class="glyphicon glyphicon-calendar"></span> Reserve now
And your reservenow.php should look somathing like this:
<?php
if (isset($_GET['new_reserve'])) {
reservenow();
}
function reservenow() {
....some sql updates here...
}?>