dmccabe Posted February 27, 2008 Share Posted February 27, 2008 Ok as some of you may have read I have been working with php & ldap. I finally got a working script that will query the ldap server which is great, but there is something wrong with the form and I dont know what. Here is the code: <html> <head> <script> function setFocus() {document.searchform.criteria.focus();} </script> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <link rel="stylesheet" type="text/css" href="default.css"> <title>Your Company Phonebook</title></head> <body onLoad="setFocus()" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0"> <table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0"> <tr> <td align="center" valign="top"> <table border="0" width="760" id="table2" cellspacing="0" cellpadding="0"> <tr> <td align="center"> <!-- this is the form that the user will input their search criteria--> <form method="GET" action="<?php echo $PHP_SELF; ?>" name="searchform"> <p>Search by: <input type="radio" value="l_name" name="params">Last Name* <input type="radio" value="f_name" name="params"> First Name* <input type="radio" value="district" name="params"> District* <input type="radio" value="exten" name="params"> Phone Extension* <input type="radio" value="all" name="params" checked> All of the Above*<br> <br> <input type="text" name="criteria" size="30"><input type="submit" value="Submit" name="B1"><br> <br> * Your search does not need to be a complete word or number, the first few letters are acceptable.</p> </form> </td> </tr> <?php require ('ldap.config.php'); //$params = "all"; //$criteria = "dar"; //if the search parameters are sent, then start the results output if ($params) { //details what to do given the different type of searches, firstname, last, etc. if ($params == "all") { $filter = "(|(sn=$criteria*)(givenname=$criteria*)(physicaldeliveryofficename=$criteria*)(telephonenumber=$criteria*))"; if (!$sort_by){$sort_by = "sn";} } elseif ($params == "f_name") { $filter = "(givenname=$criteria*)"; if (!$sort_by){$sort_by = "cn";} } elseif ($params == "l_name") { $filter = "(sn=$criteria*)"; if (!$sort_by){$sort_by = "cn";} } elseif ($params == "exten") { $filter = "(telephonenumber=$criteria*)"; if (!$sort_by){$sort_by = "telephonenumber";} } elseif ($params == "district") { $filter = "(physicaldeliveryofficename=*$criteria*)"; if (!$sort_by){$sort_by = "physicaldeliveryofficename";} } //the fields that the search will pull from in ad $get_this=array("cn", "telephonenumber", "physicaldeliveryofficename", "description", "mail", "givenname", "sn"); echo "filtering: ". $filter ."<br />"; echo "Get this: ". $get_this ."<br />"; //make the ldap connection $connect = ldap_connect( $ldap_host, $ldap_port) or exit(">>Could not connect to LDAP server<<"); //for win2003 ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3); //for win2003 ldap_set_option($connect, LDAP_OPT_REFERRALS, 0); //this is where the username and password are used to make the ldap connection $bind = ldap_bind($connect, $ldap_user, $ldap_pass) or exit(">>Could not bind to $ldap_host<<"); //search ad ldap $read = ldap_search($connect, $base_dn, $filter, $get_this) or exit(">>Unable to search ldap server<<"); //sort the results by the user specifications ldap_sort($connect, $read, $sort_by); //get the entries and put into a multi dimensional array $info = ldap_get_entries($connect, $read); echo "<tr>"; echo "<td align=\"center\">"; echo "<p align=\"left\">"; //print the number, if any, of results if ($info["count"] == 1) { echo $info["count"]." entry returned for \"$criteria\".<br><br>"; }else{ echo $info["count"]." entries returned for \"$criteria\".<br><br>"; } ?> </td> </tr> <tr> <td align="center"> <table border="1" width="100%" id="table4" bordercolorlight="#FFFFFF"> <tr> <td width="13%" bgcolor="#000080"><a style="color: #FFFFFF" href="<?php echo "$PHP_SELF?params=$params&criteria=$criteria&sort_by=sn"; ?>"><b>Last Name <? if ($sort_by == "sn" || $sort_by == "cn"){echo "»"; } ?></b></a></td> <td width="13%" bgcolor="#000080"><a style="color: #FFFFFF" href="<?php echo "$PHP_SELF?params=$params&criteria=$criteria&sort_by=givenname"; ?>"><b>First Name <? if ($sort_by == "givenname"){echo "»"; } ?></b></a></td> <td width="30%" bgcolor="#000080"><a style="color: #FFFFFF" href="<?php echo "$PHP_SELF?params=$params&criteria=$criteria&sort_by=physicaldeliveryofficename"; ?>"><b>Office <? if ($sort_by == "physicaldeliveryofficename"){echo "»"; } ?></b></a></td> <td width="22%" bgcolor="#000080"><a style="color: #FFFFFF" href="<?php echo "$PHP_SELF?params=$params&criteria=$criteria&sort_by=description"; ?>"><b>Position <? if ($sort_by == "description"){echo "»"; } ?></b></a></td> <td width="22%" bgcolor="#000080"><a style="color: #FFFFFF" href="<?php echo "$PHP_SELF?params=$params&criteria=$criteria&sort_by=telephonenumber"; ?>"><b>Phone <? if ($sort_by == "telephonenumber"){echo "»"; } ?></b></a></td> </tr> <?php //start the loop for printing the results for ($a=0; $a<$info["count"]; $a++) { //make every other row colored, feel free to change the colors if ($a % 2 == 0) { $color = "#FFFFCC"; }else{ $color = "#FFFFFF"; } $email = $info[$a]["mail"][0]; echo "<tr>"; echo "<td bgcolor=\"$color\" width=\"13%\"><a href=\"mailto:$email\" title=\"Email ".$info[$a]["givenname"][0]." ".$info[$a]["sn"][0]."\"><b>".$info[$a]["sn"][0]."</b></a> </td>"; echo "<td bgcolor=\"$color\" width=\"13%\"><a href=\"mailto:$email\" title=\"Email ".$info[$a]["givenname"][0]." ".$info[$a]["sn"][0]."\"><b>".$info[$a]["givenname"][0]."</b></a> </td>"; echo "<td bgcolor=\"$color\" width=\"30%\">".$info[$a]["physicaldeliveryofficename"][0]." </td>"; echo "<td bgcolor=\"$color\" width=\"22%\">".$info[$a]["description"][0]." </td>"; echo "<td bgcolor=\"$color\" width=\"22%\">".$info[$a]["telephonenumber"][0]." </td>"; echo "</tr>"; } //diconnect from the ldap dbase ldap_close($connect); } echo "</table>"; ?> </td> </tr> </table> </td> </tr> </table> </body> </html> Now ignore the ldap stuff as that works fine. The problem is that it never returns any results as when it checks for $params and $criteria they have no value. you can see a commented section where I have explicitly set $params and $criteria, if I uncomment those then it works perfect. what is wrong with the form? why is not passing values back? Link to comment https://forums.phpfreaks.com/topic/93340-getting-values-from-forms/ Share on other sites More sharing options...
rhodesa Posted February 27, 2008 Share Posted February 27, 2008 Change the start of the PHP part to this: <?php require ('ldap.config.php'); $params = $_GET['params']; $criteria = $_GET['criteria']; //if the search parameters are sent, then start the results output if ($params) Link to comment https://forums.phpfreaks.com/topic/93340-getting-values-from-forms/#findComment-478074 Share on other sites More sharing options...
dmccabe Posted February 27, 2008 Author Share Posted February 27, 2008 Rhodesa if I could have your babies I would !!! Thank You so much it works a treat now Link to comment https://forums.phpfreaks.com/topic/93340-getting-values-from-forms/#findComment-478089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.