0

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 :)

2
Contributors
1
Reply
14
Views
2 Years
Discussion Span
Last Post by diafol
0

I can't make much sense of this. Is all of this in one page?

I can't see how this could work. It would be useful if you described what your script was supposed to do.

However, lacking any further info, I'd probably do this:

ldap_check.php - contains ldap connection and check. If ajax request - echo output, if not, return output

page.php - page with the form and the js (jQuery reference and own script)

You have a choice with regard to the output from the call: either get raw data from the ldap and pass it to js e.g. as json and let js build the markup OR get PHP to build the entire output including markup and get js to just show it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.