I have a form that need user verifaction from ldap before being submitted. I have an ajax code for the same, to get the value of the field onchange and query ldap so that it returns the name and email id. My code is as below :
<input type="text" name="Admin_name" class="form-control" id="Admin_name" ><br/> <?php
$Name = $_POST['Supervisor_Name'];
$username="***********";
$password="***********";
$lc = ldap_connect("***********") or
die("Couldn't connect to AD!");
ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($lc,$username,$password);
$base = "OU=IMBANK-KENYA,DC=inm,DC=corp";
$filt = "(&(&(&(objectCategory=person)(objectClass=user)(name=$Name*))))";
$sr = @ldap_search($lc, $base, $filt);
$info = ldap_get_entries($lc, $sr);
for ($i = 0; $i < $info["count"]; $i++) {
//echo $address=$info[$i]["cn"][0]."<br/>" ;
//echo $address=$info[$i]["mail"][0]."<br/>" ;
//echo $address=$info[$i]["title"][0]."<br/><br/>";
//echo $address=$info[$i]["id"][0]."<br/>";
}
if ($i == 0) {
echo "No matches found!";
}
ldap_close($lc);
echo "</body></html>";
//echo $address;
?> <script>
function __change_name() {
var email = $('#select_name option:selected').attr('data-email');
$('#select_email').val(email);
}
</script> <select name= "name" id="select_name" onchange="__change_name()"> <?php
for ($i = 0; $i < $info['count']; $i++) {
echo '<option value="' . $info[$i]['sn'][0] . ', ' . $info[$i]['givenname'][0] . '" data-email="' . $info[$i]['mail'][0] . '">' . $info[$i]['sn'][0] . ', ' . $info[$i]['givenname'][0] . '</option>';
}
?> </select> <input type="text" name="email" id="select_email">
But this doesn't seem to work. Where am I going wrong? Appreciate any help :)