Customized Search Form

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
Yilmaz
Posts: 22
Joined: 2013-01-24 16:58

Customized Search Form

Post by Yilmaz » 2013-04-08 15:47

Dear Forum,

I created a customized search form with 2 different text fields and it works so far very fine.

My problem is: If the user enters an empty string and clicks on the submit button the tablename_view.php lists all the records!

Therefore I tried a php and javascript solution to show an allert, for example "You have to fill all fields!", but unfortunatelly it doesn't work!

Does anyone have an idea? here is my code:

In the hooks-folder my tablename_filter.php file (PHP validation is commented out!)

Code: Select all

<?php
/*
$feld1 = $_POST['FilterAnd'][1];
$feld2 = $_POST['FilterField'][1];
$feld1 = $_POST['FilterOperator'][1];
$feld1 = $_POST['FilterValue'][1];

echo "feld1 = " .$feld1."<br />";
echo "feld2 = " .$feld2."<br />";
echo "feld3 = " .$feld3."<br />";
echo "feld4 = " .$feld4."<br />";

if (isset($feld) && $feld != "") {
	echo "Sehr gut!";
}
else {
	if (isset($senden)) {
		echo "Bitte alle Felder ausfuellen!!";
	}
}


if (isset($senden)) {
		echo "Halloooo???!!";
	} 
else {
	if (isset($senden) or isset($feld) or empty($feld)) {
		echo "Bitte alle Felder ausfuellen!";
	}	
}
*/	
?>

<div style="text-align:center !important" class="TableTitle"><span id="table-title-img"><img align="top" src="table.gif"></span> NPS Kunden by Nikon IT<br /><br /></div>
<div id="npsfilter">
<table align="center">
<tr>
<!-- Filter fuer NPS-Nr. -->
	<td style="font-family:verdana;font-size:16px:font-weight:bold;"><b>NPS-Nummer:</b></td>
	<td><input name=FilterAnd[1] value='' type=hidden></td>
	<td><input name=FilterField[1] value='1' type=hidden></td>
	<td><input name=FilterOperator[1] value='<=>' type=hidden></td>
	<td><input name=FilterValue[1] value='' type=text></td>
</tr>
<tr>
<td style="font-family:verdana;font-size:14px:font-weight:bold;">oder</td><td>&nbsp;</td>
</tr>
<tr>
<!-- Filter fuer Kunden-Nachname -->
	<td style="font-family:verdana;font-size:16px:font-weight:bold;"><b>NPS-Kunden-Nachname:</b></td>
	<td><input name=FilterAnd[2] value='' type=hidden></td>
	<td><input name=FilterField[2] value='2' type=hidden></td>
	<td><input name=FilterOperator[2] value='<=>' type=hidden></td>
	<td><input name=FilterValue[2] value='' type=text></td>
</tr>	
<tr>
<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td><input id ="finden" type=submit name="senden" value="Finden"></td>
</tr>
</table>
</div>

<div class="TableFooter">
<?php 
    echo "Letzte NPS-Datenbank-Aktualisierung: " . date("d.m.Y - H:i", filemtime("importkunden/ybc.php"));
?>
</div>

I modified the tablename.php file in the hooks-folder within the tablename_init function so that the filter-click in the table view redirects the user to the customized filterpage:

Code: Select all

	function nps_kunden_init(&$options, $memberInfo, &$args){
		// Die neue individuelle Such-Seite aktivieren
		$options->FilterPage = dirname(__FILE__).'/nps_kunden_filter.php';
		
		return TRUE;
	}
Thanks a lot
Yilmaz

Yilmaz
Posts: 22
Joined: 2013-01-24 16:58

Re: Customized Search Form

Post by Yilmaz » 2013-04-09 14:00

One additional remark:

I added a little javascript code (if condition part) within the datalist.php:

Code: Select all

		$this->HTML .= '<form method="post" name="myform" action="'.$this->ScriptFileName.'">';
		$this->HTML .= '<script>';
		$this->HTML .= 'function enterAction(){';
		$this->HTML .= '   if($$("input[name=SearchString]:focus")[0] != undefined){ $("Search").click(); }';
		$this->HTML .= '   return false;';
		$this->HTML .= '}';
		$this->HTML .= '</script>';
		$this->HTML .= '<input id="EnterAction" type="submit" style="position: absolute; left: 0px; top: -100px;" onclick="return enterAction();">';

		if (empty($_POST['FilterValue'][1]) or empty($_POST['FilterValue'][2])) {
			echo '<script type="text/javascript" language="Javascript"> 
			alert("Bitte fuellen Sie eins der beiden Felder aus!") 
		  </script> '; 
		}
	
		$this->ContentType='tableview'; // default content type:
So I can now process the input text fields (empty or not --> alert-text) but the user gets stil whole the records in the table view instead only the alert message (in case of empty fields)!

Any idea?

Yilmaz

Yilmaz
Posts: 22
Joined: 2013-01-24 16:58

SOLVED: Re: Customized Search Form

Post by Yilmaz » 2013-04-12 13:34

The following solution has fixed my problem:

- I modified the if condition in datalist.php as followed:

Code: Select all

		$this->HTML .= '<form method="post" name="myform" action="'.$this->ScriptFileName.'">';
		$this->HTML .= '<script>';
		$this->HTML .= 'function enterAction(){';
		$this->HTML .= '   if($$("input[name=SearchString]:focus")[0] != undefined){ $("Search").click(); }';
		$this->HTML .= '   return false;';
		$this->HTML .= '}';
		$this->HTML .= '</script>';
		$this->HTML .= '<input id="EnterAction" type="submit" style="position: absolute; left: 0px; top: -100px;" onclick="return enterAction();">';
		
		//YBC: validate the filter fields for empty - JavaScript or PHP method
		if (isset($_POST['senden']) && (empty($_POST['FilterValue'][1]) and empty($_POST['FilterValue'][2]) and empty($_POST['FilterValue'][3]))) {
			echo '<script type="text/javascript" language="Javascript"> 
			alert("Bitte fuellen Sie eins der beiden Felder aus!") 
			window.location.href = "http://localhost/nps2/nps_kunden_view.php?t=1365405232&Filter_x=1";
		  </script> '; 
		 // header("Location: http://yourdomain.com/nps_kunden_view.php?t=1365405232&Filter_x=1");
		}	
If the filter fields are empty AND submit button has been clicked --> alert message and call the filterpage again.

I recommend to use the PHP variant because JavaScript can be disabled locally by the user. In that case comment out the line:
header("Location: http://yourdomain.com/nps_kunden_view.p ... Filter_x=1");

Regards,

Yilmaz

KSan
AppGini Super Hero
AppGini Super Hero
Posts: 252
Joined: 2013-01-08 20:17

Re: Customized Search Form

Post by KSan » 2013-04-13 00:10

Great job finding a solution to your problem / question. It is wonderful that you took the time to share your solution with all other members. Thank you!!!

Post Reply