Commit f46774c7 authored by Romain Loth's avatar Romain Loth

small harmonizations for validation on client-side

parent 584c89a3
......@@ -159,23 +159,14 @@ if __name__ == "__main__":
got_them_all = None
if captcha_accepted:
expected = ['email', 'hon_title', 'first_name', 'middle_name',
'last_name', 'initials', 'keywords', 'country',
'organization']
columns = ['email', 'initials']
# read in + sanitize values
# =========================
# NB password values have already been sent by ajax to Doors
# TODO redundant with js validation ?
# we should have all the mandatory fields (checked in client-side js)
for field in COLS:
if field in incoming_data:
if (field in incoming_data) and (field != pic_file):
clean_records[field] = sanitize(incoming_data[field].value)
else:
missing_fields.append(field)
# --------- todo ------>8--------------
# optional
......@@ -184,18 +175,8 @@ if __name__ == "__main__":
# picture_bytes = picture.value
# --------------------->8---------------
# debug data keys
# print([k for k in incoming_data])
# NB will be done in js
got_them_all = True
for k in columns:
if k in missing_fields:
got_them_all = False
break
# sanitize & save to DB
# =====================
# save to DB
# ===========
save_to_db([clean_records[k] for k in columns])
......@@ -207,7 +188,7 @@ if __name__ == "__main__":
# for debug
records = clean_records,
message = "got_them_all:" + str(got_them_all)
message = ""
)
)
......
......@@ -24,6 +24,8 @@ var COLS = [ ["doors_uid", false, 36, 'exact'],
var wholeFormData
var theForm = document.getElementById('comex_reg_form')
var regTimestamp = document.getElementById('last_modified_date')
var uidInput = document.getElementById('doors_uid')
var email = document.getElementById('email')
var subPage1Style = document.getElementById('subpage_1').style
var subPage2Style = document.getElementById('subpage_2').style
......@@ -56,9 +58,12 @@ var emailStatus = false
var captchaStatus = false
submitButton.disabled = true
theForm.onkeyup = beTestedAsYouGo
theForm.onchange = beTestedAsYouGo
// done when anything in the form changes
function beTestedAsYouGo() {
basicEmailValidate()
captchaStatus = (captcha.value.length == realCaptchaLength)
if (passStatus && emailStatus && captchaStatus) {
submitButton.disabled = false
}
......@@ -157,6 +162,7 @@ function validateSubmit(e, orignStr, loginOrRegister) {
doorsUid = makePseudoDoorsUid()
// 3) fill in the answer we got
wholeFormData.set("doors_uid", doorsUid)
uidInput.value = doorsUid // todo feels redundant (=> refactor submit into FormData send ?)
// 4) here entire validation
......@@ -214,6 +220,9 @@ function validateSubmit(e, orignStr, loginOrRegister) {
// 5) RESULTS
if (valid) {
// add the captchaCheck inside the form (jquery interference)
captchaCheck.value = $(captcha).realperson('getHash')
mainMessage.innerHTML = "Form is valid... Submitting..."
mainMessage.style.display = 'block'
theForm.submit()
......@@ -340,10 +349,7 @@ nameInputs.forEach ( function(nameInput) {
// very basic email validation TODO: better extension and allowed chars set :)
var email = document.getElementById('email')
email.onkeyup = basicEmailValidate
email.onblur = basicEmailValidate
// (used in tests "as we go")
function basicEmailValidate () {
emailStatus = /^[-A-z0-9_=.+]+@[-A-z0-9_=.+]+\.[-A-z0-9_=.+]{1,4}$/.test(email.value)
}
......@@ -389,12 +395,6 @@ passwords.forEach ( function(pass) {
})
var captcha = document.getElementById('my-captcha')
captcha.onkeyup = function() {
captchaStatus = (captcha.value.length == realCaptchaLength)
}
// autocomplete countries
$(function() {
var $countryInput = $('#country')
......@@ -624,6 +624,7 @@ $('#my-captcha').val('')
$(function() {
var $kwInput = $('#keywords')
// TODO transform into simple array => faster
var kwFreqs = {
"complex networks": 154,
"complex systems": 134,
......@@ -983,3 +984,5 @@ $(function() {
}
});
});
console.log("load OK")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment