Skip to content

Commit ff8f107

Browse files
Ajax Query to Submit Form
1 parent 0670847 commit ff8f107

19 files changed

+85
-6
lines changed
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
44 Bytes
Binary file not shown.
536 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

MMIL_Website_V3/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from django.contrib import admin
1717
from django.urls import path
1818
from .views import index,about,project,event,team,contact,gallery,zealicon
19-
from registration.views import registration
19+
from registration.views import registration,create_register
2020

2121

2222

@@ -31,5 +31,6 @@
3131
path('gallery/',gallery),
3232
path('zealicon/',zealicon),
3333
path('register',registration),
34+
path('create',create_register)
3435

3536
]

MMIL_Website_V3/views.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,35 @@
33
from .forms import contact_form
44
from django.core.mail import send_mail,EmailMultiAlternatives
55
from .settings import EMAIL_HOST_USER
6+
from registration.models import Student_Registration
67

78

89
def index(request):
10+
if request.POST:
11+
print(request.POST)
12+
name=request.POST.get('name')
13+
admission_no=request.POST.get('adm_no')
14+
department=request.POST.get('department')
15+
branch=request.POST.get('branch')
16+
year=request.POST.get('year')
17+
email=request.POST.get('email')
18+
contact=request.POST.get('contact')
19+
leng=len(department)
20+
print(type(department))
21+
interests=''
22+
for i in range(leng):
23+
interests=interests+department[i]+','
24+
register_data=Student_Registration(
25+
name=name,
26+
admission_no=admission_no,
27+
interests=interests,
28+
branch=branch,
29+
year=year,
30+
email=email,
31+
phone_no=contact
32+
)
33+
register_data.save()
34+
return redirect('/')
935
return render(request, "index/index.html",{})
1036

1137

db.sqlite3

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
547 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

registration/views.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,36 @@
66

77

88
def registration(request):
9+
if request.POST:
10+
print(request.POST)
11+
name=request.POST.get('name')
12+
admission_no=request.POST.get('adm_no')
13+
department=request.POST.getlist('department')
14+
branch=request.POST.get('branch')
15+
year=request.POST.get('year')
16+
email=request.POST.get('email')
17+
contact=request.POST.get('contact')
18+
leng=len(department)
19+
print(type(department))
20+
interests=''
21+
for i in range(leng):
22+
interests=interests+department[i]+','
23+
register_data=Student_Registration(
24+
name=name,
25+
admission_no=admission_no,
26+
interests=interests,
27+
branch=branch,
28+
year=year,
29+
email=email,
30+
phone_no=contact
31+
)
32+
register_data.save()
33+
return redirect('/')
34+
return render(request, "register/register.html",{})
35+
36+
37+
38+
def create_register(request):
939
if request.POST:
1040
print(request.POST)
1141
name=request.POST.get('name')
@@ -30,5 +60,4 @@ def registration(request):
3060
phone_no=contact
3161
)
3262
register_data.save()
33-
return redirect('/')
34-
return render(request, "register/register.html",{})
63+
return HttpResponse('')

static_mmil/js/register.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,35 @@ window.onload = function(){
55
// submitCallback: function(){
66
// // alert("Submit: check dev tools console for more");
77
// // be aware that this prevents default form submit.
8-
// // var formData = conversationalForm.getFormData();
8+
var formData = conversationalForm.getFormData();
99
// // var formDataSerialized = conversationalForm.getFormData(true);
1010
// // console.log("Formdata:", formData);
1111
// // console.log("Formdata, serialized:", formDataSerialized);
1212
// conversationalForm.addRobotChatResponse("It was nice meeting you. See you at the recruitments. 😊😊😊");
1313
// conversationalForm.addRobotChatResponse("Good Bye!!!");
14+
// // setTimeout("location.href = '/';",1500);
1415
// }
16+
$(document).on('submit','#form',function(e){
17+
e.preventDefault();
18+
$.ajax({
19+
type:'POST',
20+
url:'/create',
21+
data:formData,
22+
success:function(){
23+
alert("Form Submitted");
24+
}
25+
});
26+
});
1527
});
16-
};
28+
};
29+
30+
// $(document).ready(function() {
31+
// $('#form').submit(function() { // catch the form's submit event
32+
// $.ajax({ // create an AJAX call...
33+
// data: $(this).serialize(), // get the form data
34+
// type: $(this).attr('method'), // GET or POST
35+
// url: $(this).attr('action'), // the file to call
36+
// });
37+
// return false;
38+
// });
39+
// });

templates/register/register.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/space10-community/[email protected]/dist/conversational-form.min.js" crossorigin></script>
201201
</head>
202202
<body>
203-
<form id="form" method="POST" cf-form>{% csrf_token %}
203+
<form id="form" method="POST" action="/register" cf-form>{% csrf_token %}
204204
<cf-robot-message cf-questions="Hello, my friend!!!"></cf-robot-message>
205205
<cf-robot-message cf-questions="Let's get started"></cf-robot-message>
206206
<fieldset>

0 commit comments

Comments
 (0)