Jump to content

Getting values from forms?


dmccabe

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.