Code: Select all
// var_name = name of variable used in form
// var_type = type of variable (integer, string, bool, etc.)
// form_code = html code used in search form
// php_code = php code used in checking the variable
// $var_list = array( array( "name" => "var_name", "type" => "var_type_int_str_bool", "form_code" = "html_code" , "php_code" => "php code") );
$name = "zip";
$type = "INT";
$form_code = $name.': <input type="text" name="'.$name.'" class="search" />';
$php_code = '$row[\'name\'] : $_SESSION[$name]'; //HAVING PROBLEMS HERE
$zip_code = array( "name" => $name, "type" => $type, "form_code" => $form_code, "php_code" => $php_code );
$var_list = array($zip_code);
main_search( $var_list );
Code: Select all
// This is the code for the searchbox. Basically, it checks to see what criteria are being searched by
// and gives a list current criteria with the option to eliminate any existing criteria. Below, that is
// criteria that can be searched by but is not currently being used in the search. Each click of the
// submission button or the delete button will add or remove criteria. Note that the buyer and seller
// will have somewhat different search criteria.
function main_search($var_list)
{
// var_name = name of variable used in form
// var_type = type of variable (integer, string, bool, etc)
// form_code = html code used in search form
// php_code = php code used in checking the variable
// $var_list = array( array( "name" => "var_name", "type" => "var_type_int_str_bool", "form_code" = "html_code" , "php_code" => "php code") );
// Next we check if any new criteria have been submitted. If so, then we will store the criteria in
// the $_SESSION array so that it is temporarly avaaible whilst the session is active. Note that we
// cycle through all the variables in out search list.
foreach ($var_list as $row)
{
if ( isset( $_POST[$row['name']] ) === TRUE )
{
$_SESSION[$row['name']] = $_POST[$row['name']];
}
}
// If the user resets the form at the bottom, then we delete all the current criteria.
// To do that, we must cycle through it by checking if the criteria is active and, if so, deleting it.
if ( $_POST['update'] == "reset" )
{
foreach ($var_list as $row)
{
if ( isset( $_SESSION[$row['name']] ) === TRUE )
{
unset( $_SESSION[$row['name']] );
}
}
}
// If the X button is pressed next to an active criteria, it will be deleted. The buttons should have
// the name "delete" and their var_name as their value.
if ( isset( $_POST['X'] ) === TRUE )
{
unset( $_SESSION[$_POST['X']] );
}
// Now we begin the actual form code which contains both the active criteria and the unused criteria.
$currentpage = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
echo '<form name="search" action="'.$currentpage.'" method="post">';
// We want to search through all the criteria to see which ones have active $_SESSION variables.
// Those will be displayed with their current value and a way to delete them.
foreach ($var_list as $row)
{
if ( isset( $_SESSION[$row['name']] ) === TRUE )
{
$php_code = eval($row['php_code']);
echo '<span class="search_criteria">'.$php_code.'</span>';
echo '<input type="submit" name="'.$row['name'].'" value="X" class="delete_criteria">';
$vars_exist = FALSE; // unused criteria are set to FALSE here anytime at least 1 criteria is beign searched
}
}
// Now, we look for all the criteria that do NOT have active $_SESSION variables. Those are ones
// that can be searched through.
foreach ($var_list as $row)
{
if ( isset( $_SESSION[$row['name']] ) === FALSE )
{
echo $row["form_code"];
$vars_exist = TRUE; // there exists an unused criteria so we know that there is still free vars
}
}
// here we add the search button but only when it is still possible to search using criteria
if ( $vars_exist === TRUE )
{
echo '<input type="submit" name="update" value="submit">';
}
// users should always have the option to reset the form even if they have not searched
// this way they can reset a form that may be filled in but incorrectly so
echo '<input type="submit" name="update" value="reset">';
echo '</form>';
}
Code: Select all
// We want to search through all the criteria to see which ones have active $_SESSION variables.
// Those will be displayed with their current value and a way to delete them.
foreach ($var_list as $row)
{
if ( isset( $_SESSION[$row['name']] ) === TRUE )
{
$php_code = eval($row['php_code']);
echo '<span class="search_criteria">'.$php_code.'</span>';
echo '<input type="submit" name="'.$row['name'].'" value="X" class="delete_criteria">';
$vars_exist = FALSE; // unused criteria are set to FALSE here anytime at least 1 criteria is beign searched
}
}