Django server side AJAX validation
- by MMRUser
Hi,
Recently I'm trying to implement a simple Django application that include one server side AJAX validation, it's a simple form input field (username). I have used a pre-built in line AJAX validation library which uses jQuery. So the code goes like this
HTML snippet
<form id="simpleform" method="post" action="/done/">
Username:<input value="" class="validate[required,custom[noSpecialCaracters],length[0,20],ajax[ajaxUser]]" type="text" name="user" id="user" />
<input class="submit" type="submit" value="Validate"/>
</form>
The server side code snippet (embedded in to a php script)
/* RECEIVE VALUE */
$validateValue=$_POST['validateValue'];
$validateId=$_POST['validateId'];
$validateError=$_POST['validateError'];
/* RETURN VALUE */
$arrayToJs = array();
$arrayToJs[0] = $validateId;
$arrayToJs[1] = $validateError;
if($validateValue =="testname"){ // validate??
$arrayToJs[2] = "true"; // RETURN TRUE
echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}'; // RETURN ARRAY WITH success
}else{
for($x=0;$x<1000000;$x++){
if($x == 990000){
$arrayToJs[2] = "false";
echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}'; // RETURN ARRAY WITH ERROR
}
}
}
So my question is that how do I get this in to Python code (in order to use in Django environment) how do I get the user name from the input field in to the back end,I think the server side script snippet already does it but I want to know how to use this in my Pyhon code,and this is my first time using jQuery and I do need to use this same exact validation library. Your valuable corporation is needed.
Thanks.