Wednesday, July 11, 2007

Submit form with jQuery

Submit form with jQuery


posting.php file
<script language="javascript" src="js/jquery-1.6.3.min.js" type="text/javascript"></script>
<form id="myform" name="myform" action="postdata.php" method="post">
  <input type="text" id="nm" name="nm" />
  <input type="submit" value="Go" />
  <span id="errorspan"></span>
</form>
<div id="banner">
  Submit form with jQuery.
</div>
<script>
$('#myform').submit(function() {
  if($("#nm").val()=="") {
      $("#errorspan").text("Not valid!").show().fadeOut(3000);
      return false;
  } else {
      return true;
  }
});

$('#banner').click(function() {
  $('#myform').submit();
});
</script>



postdata.php file
<?php
echo $_POST['nm'];


?>


Wednesday, July 4, 2007

Show all objects of LDAP Server in PHP

Show all objects of LDAP Server in PHP

<?php
//$ldapServer = "ldap://111.222.111.222:389";

$ldapServer = '111.222.111.222';
$ldapBase = 'DC=abc,DC=com';
$ldapConn = ldap_connect($ldapServer);
if (!$ldapConn)
{
  die('Cannot Connect to LDAP server');
}
$ldapBind = ldap_bind($ldapConn);
if (!$ldapBind) {
  die('Cannot Bind to LDAP server');
}
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapSearch = ldap_search($ldapConn, $ldapBase, "(cn=*)");
$ldapResults = ldap_get_entries($ldapConn, $ldapSearch);
for ($item = 0; $item < $ldapResults['count']; $item++) {
  for ($attribute = 0; $attribute < $ldapResults[$item]['count']; $attribute++) {
    $data = $ldapResults[$item][$attribute];
    echo $data.":&nbsp;&nbsp;".$ldapResults[$item][$data][0]."<br>";
  }
  echo '<hr />';
}
?>