+1 571-297-6383 | info@sonjara.com

Chapter 7. Search Forms

The Fakoli SearchForm class extends AutoForm to provide a web form for database searches. With SearchForms where the input fields represent search values rather than data values.

Using our task example, the following code would create a Search Form to search the database for a specified project and/or title:

$task = new Task();
$task->filter = new InclusionFilter("project_id", "title");

$form = new SearchForm($task, "GET", "task_results.php");

$form->setMatchingMode("startsWith", "title");

$projRenderer = new RelatedItemSelectFieldRenderer($form, "project_id", 
	"Projects", Project, "ORDER BY project_name",
	"project_name", "project_id");

echo $form->writeScript();

The SearchForm parameters specify that the form should render the fields in $task and provide the results to the script task_results.php using GET. The setMatchingMode() function specifies one of the following types of matches:

  • equal requires an exact match; default matching mode for numeric fields
  • like matches must contain the search string; default matching mode for string fields
  • startsWith matches must start with the search string
  • from the lower end of a range match
  • to the upper end of a range match

The resulting web form is shown below:

Search Form Example 1

The SearchForm class calls the renderSearchField() function of the FieldRenderer class for each of the fields included in the form. The renderSearchField function creates the HTML for the search field, specifying the desired matching mode. If we wished to search for all ACME Printing projects that start with the letter D, we would enter the following values into the search form and click Search Tasks.

Search Form Example 2

The results of the search would be shown on the task_results.php list page which could display results in table format using the ListView class, as described in the next chapter.

Chapter 8. List Views » « Chapter 6. Automated Web Forms