Framework  3.9
SearchForm Class Reference

SearchForm generates forms for searching based on a supplied DataItem. More...

+ Inheritance diagram for SearchForm:
+ Collaboration diagram for SearchForm:

Public Member Functions

 SearchForm ($target, $method="POST", $action="", $id="")
 Create a new Search Form. More...
 
 setMatchingMode ($mode)
 Sets the matching mode for the specified fields. More...
 
 getMatchingMode ($field)
 Retrieve the matching mode that was set for the specified field. More...
 
 populateFromGET ()
 Populate the search parameters from an HTTP GET request. More...
 
 populateFromPOST ()
 Populate the search parameters from an HTTP POST request. More...
 
 populateFromREQUEST ()
 
 setHandler ($field, $handler)
 Override an existing SearchParameter constraint clause handler or add one. More...
 
 writeScript ()
 Generate any javascript required by the search form. More...
 
 addDefaultValidators ()
 Creates default validators for fields in the form. More...
 
 setSearchValidator ($renderer, $field, $mode)
 After AutoForm configures the validators, modify the field name to include the mode with which the tag will drawn in the form. More...
 
 drawForm ()
 Write out the HTML for the search form. More...
 
 renderSearchFields ()
 
 renderOneSearchField ($field)
 
 renderAdditionalFields ($obj)
 
 drawReadOnly ()
 Draws the form in read-only mode. More...
 
- Public Member Functions inherited from AutoForm
 AutoForm ($target, $method="POST", $action="", $id="")
 Creates a new AutoForm, based on the supplied target DataItem. More...
 
 getData ()
 Returns the target data item for the form. More...
 
 setDataSet ($params)
 
 setLayout ($layout)
 Override the default layout manager. More...
 
 setFieldOrder ()
 Override the display order for ungrouped field. More...
 
 createRenderer ($field)
 This factory method creates a FieldRender based on the type of the specified field. More...
 
 getValidationEngine ()
 Retrieve the validation engine for this AutoForm. More...
 
 makeSubordinate ()
 Set this AutoForm to be a subordinate form within a CompositeAutoForm. More...
 
 configureValidators ()
 
 getRenderer ($field)
 Retrieves the FieldRenderer object for the specified field. More...
 
 override ($field, $label="", $renderer=null)
 Overrides the defaults for the specifed form field, providing a new label and/or FieldRenderer. More...
 
 overrideType ($field, $type, $label="")
 Override the default type for the specified form field, providing a FieldRenderer based on the supplied type (and optionally also override the field label) More...
 
 add ($renderer, $field="", $label="")
 Adds an additional (pseudo) field to the form. More...
 
 hide ()
 Call this method to hide one or more fields in the form's user interface. More...
 
 hideExcept ()
 Call this method to hide all the fields in the form's user interface EXCEPT the fields specified. More...
 
 isHidden ($field)
 Check whether the specified field is hidden in the form. More...
 
 annotate ($field, $text)
 Adds an annotation (such as brief explanatory text) to the specified field. More...
 
 alias ()
 Use this method to override the display name for fields in the form. More...
 
 related ($class, $constraint="", $format=null, $field=null, $label=null, $allowAdd=false, $allowNone=true)
 Utility function to add a RelatedItemSelectFieldRender. More...
 
 crossReference ($xrefClass, $options, $format, $field, $label=null, $xrefField=null)
 Utility function to add a CrossReferenceSelectFieldRenderer. More...
 
 dropdown ($field, $label="", $options=null, $onchange=null, $grouped=false)
 Utility function to add a SelectFieldRenderer. More...
 
 groupedDropdown ($field, $label, $options, $onchange=null)
 Utility function to add a SelectFieldRenderer with grouped options. More...
 
 radio ($field, $label, $options, $onchange=null)
 Utility function to add a RadioButtonFieldRenderer. More...
 
 checklist ($field, $label, $options, $grouped=false)
 Utility function to add a CheckListFieldRenderer. More...
 
 toggle ($field, $label="", $ragged=false)
 Utility function to create a ToggleFieldRenderer. More...
 
 group ($name)
 Define a field grouping. More...
 
 addToGroup ($name)
 Add more fields to the specified group. More...
 
 groupDescription ($name, $description, $position='start')
 Add a description block to a group. More...
 
 getGroupDescription ($name, $position='start')
 Retrieves the group description for the specified group. More...
 
 makeGroupCollapsible ($name, $toggleControl)
 Allows a group to be shown or hidden based on the value of another control. More...
 
 setGroupCSSClass ($name, $cssClass)
 Sets a specific CSS class on the specified CSS group. More...
 
 getGroupCSSClass ($name)
 Gets the CSS class for the specified group, if one has been set. More...
 
 removeGroup ($name)
 Remove the specified field grouping from the form. More...
 
 hideLabel ()
 Use this method to hide the labels for the specified fields in the form. More...
 
 readonly ()
 Call this method to make one or more fields read-only in the form's user interface. More...
 
 isReadOnly ($field)
 Determine whether the specified field is being displayed read-only. More...
 
 required ()
 Call this method to mark one or more fields as being required fields. More...
 
 hasAdditional ($field)
 Check if this field exists as an additional field. More...
 
 isRequired ($field)
 Determine whether the specified field is a required field for the form. More...
 
 requiredIfChecked ($field, $checkbox, $fieldTitle="", $checkboxTitle="", $message="")
 Make a field required if a given checkbox is checked. More...
 
 requiredSubSelect ($field, $fieldTitle, $subFieldTitle="", $message="")
 Make a subselect field required. More...
 
 regexp ($field, $expr, $message)
 Validate the user input for the specified field against a regular expression, outputting the supplied message if the entered value does not match. More...
 
 dateRange ($field, $min="", $max="", $message=null)
 
 unique ()
 Adds a uniqueness validator to the specified field(s). More...
 
 uniqueWithConstraint ($field, $message, $constraint="")
 
 range ($field, $min, $max, $message=null)
 Adds a range validator to the specified field. More...
 
 match ($field, $title, $match, $matchTitle, $caseSensitive=true)
 Specifies that two field values must match (as in a password/confirmation pair, for instance). More...
 
 password ($field, $title)
 Adds a password validator to the specified field. More...
 
 disableAutoComplete ()
 Disable autocomplete for the selected fields. More...
 
 button ($text, $url, $confirm=null, $isScript=false, $cssClass=null)
 Adds a custom button to the form. More...
 
 ajaxSubmit ($success, $failure=null)
 Put the form into AJAX submission mode. More...
 
 partialSaveButton ($containerID, $label="Save")
 Activate partial saves for this form. More...
 
 matchesSubmitted ()
 Determine if this form is the one that was submitted. More...
 
 drawSubmitButtons ($obj, $pk, $submitLabel)
 
 renderAllFields ($obj)
 
 renderFields ($obj)
 
 renderOneField ($field, $renderScript=false)
 
 drawButtons ()
 Draws any additional buttons specified in the calling script. More...
 
 prettifyFieldName ($field)
 Generates a human-readable label from the given field name. More...
 
 load ($id)
 Loads the underlying DataItem from the database, using the specified primary key value. More...
 
 save ()
 Saves the posted values to the database. More...
 
 handlePartialSave ($success)
 
 preProcessFields ($pk, $filter)
 
 postProcessFields ($pk, $filter)
 
 remove (&$obj)
 
 validate ()
 Validate the posted values for the form. More...
 
 patchUpReferences ()
 

Public Attributes

 $modifiers
 
 $params
 
 $hasSearchCriteria = false
 
 $emptyMessage = "No search criteria was provided."
 
 $preserveQueryString = false
 
 $searchModeTypes
 
- Public Attributes inherited from AutoForm
 $formCSS = ""
 CSS Class to use for the table containing the form. More...
 
 $labelCSS = ""
 CSS Class to use for label cells. More...
 
 $valueCSS = ""
 CSS Class to use for field/value cells. More...
 
 $buttonCSS = ""
 CSS Class to use for buttons. More...
 
 $buttonLineCSS = "submit"
 CSS Class to use for the button line (container for form buttons) More...
 
 $inputCSS = ""
 CSS Class to use for input fields. More...
 
 $checkboxCSS = ""
 CSS Class to use for checkbox fields. More...
 
 $style = ""
 
 $componentPath ="/fakoli"
 
 $buttonAlignment = "left"
 Default Form button alignment. More...
 
 $passwordEncryptor = ""
 Password Encryption method name. More...
 
 $hideButtons = false
 Set to true to hide form submission button line(s) More...
 
 $capitalizationMode = "word"
 Capitalization to be used for labels. Can be 'lower', 'upper', 'first' or 'word'. More...
 
 $submitLabel = ""
 Text to display on the form's submit button. If not specified defaut text will be generated based on the target DataItem. More...
 
 $allowDelete = false
 If true, the form will display a delete button if editing an existing item. More...
 
 $deleteLabel = ""
 Text to display on the form's delete button. If not specified defaut text will be generated based on the target DataItem. More...
 
 $deleteMessage = ""
 Confirmation message to display when the form's delete button is pressed. If not specified defaut text will be generated based on the target DataItem. More...
 
 $method = "POST"
 HTTP method that will be used to submit the form. More...
 
 $action = ""
 Action URL for submitting the form. Generally this can be left blank to submit back to the same page. More...
 
 $renderers = array()
 The field renderers collection. More...
 
 $overrides = array()
 The field overrides collection. More...
 
 $hidden = array()
 The hidden fields collection. More...
 
 $additional = array()
 The additional (pseudo) fields collection. More...
 
 $additional_at_top = false
 whether additional fields are rendered above the datamodel's field list; if false, then rendered below More...
 
 $readonly = array()
 The read-only fields collection. More...
 
 $annotations = array()
 The field annotations collection. More...
 
 $buttons = array()
 The custom buttons collection. More...
 
 $fieldOrder = array()
 The order in which to display ungrouped fields. More...
 
 $validator
 The ValidationEngine for this form. More...
 
 $useLinkSubmit = false
 Flag to indicate whether the submit button for the form should be rendered as a link (not common). More...
 
 $HTMLEditorHideStyleBar = false
 Flag to indicate that Rich Text Editors should be displayed with or without the style editing toolbar. More...
 
 $HTMLEditorDefaultWidth = "540px"
 Default width for Rich Text Editor controls. More...
 
 $HTMLEditorDefaultHeight = "200px"
 Default height for Rich Text Editor controls. More...
 
 $passwordEnterLabel = "Enter"
 Text for Password Enter label. More...
 
 $passwordConfirmLabel = "Confirm"
 Text for Password Confirm label. More...
 
 $onDrawStart = null
 Callback event handler that is fired just prior to drawing the form. More...
 
 $onDrawComplete = null
 Callback event handler that is fired just after the form been drawn. More...
 
 $onInsertPreProcess = null
 Callback event handler that is fired after fields have been preprocessed, but before the data has been saved to the database as a new record. More...
 
 $onSavePreProcess = null
 Callback event handler that is fired after fields have been preprocessed, but before the data has been saved to the database. More...
 
 $onSaveComplete = null
 Callback event handler that is fired after the AutoForm has finished saving data to the database. More...
 
 $confirmPrompt = null
 Specify a confirmation message. This will be shown to the user to have them confirm the form submission after the submit button is pressed. More...
 
 $onDelete = ""
 delete method name More...
 
 $customSaveHandler = null
 Use this field to override the default save behavior of your form. More...
 
 $markRequiredFields = false
 Set to true to add an asterisk after required field labels. More...
 
 $onFormatLabel = null
 Label Processing hook. More...
 
 $buttons_at_top = false
 
 $ajaxSubmitHandler = false
 JavaScript Callback for AJAX Submit mode - called on success. More...
 
 $ajaxFailureHandler = false
 JavaScript Callback for AJAX Submit mode - called on failure. More...
 
 $onSubmitHandler = null
 Javascript Callback for user-defined onsubmit hook. More...
 
 $required = array()
 List of required fields. More...
 
 $requiredFieldsText = "* indicates required field"
 Text prompt to display when a form contains required fields. More...
 
 $interstitialMessage = null
 Specifies the message to display in an interstitial while the form is being submitted. More...
 
 $interstitialSpinner = '/fakoli/images/loader.gif'
 Set this property to override the default interstitial spinner animation. More...
 
 $fields
 Local field cache. More...
 
 $groups = array()
 List of field groups. More...
 
 $collapsibleGroups = array()
 List of collapsible groups and their default states. More...
 
 $groupDescriptions = array()
 List of group descriptions. More...
 
 $groupDescriptionCSS = "group_description"
 CSS class for group description blocks. More...
 
 $groupCSSClasses = array()
 Additional classes for specific groups. More...
 
 $readOnlyForm
 Specifies whether the entire form is read-only. More...
 
 $subordinate
 Specifies whether this form is a subordinate member of a composite form. More...
 
 $hideEmptyFields = false
 Specifies whether to hide empty fields when displaying a read-only form. More...
 
 $showAnnotations = true
 Set to false to hide field annotations. More...
 
 $layout
 Layout handler object. More...
 
 $default_layout = "table"
 
 $allowPartialSave = false
 Whether to allow partial (i.e. in-progress) saves via AJAX. More...
 
 $partialSaveContainerID
 DOM ID for the element that will contain the partial save button. More...
 
 $partialSaveLabel = "Save"
 Label text for the partial save button. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from AutoForm
static registerFieldRendererClass ($type, $rendererClass)
 Registers a custom type-to-renderer mapping. More...
 
- Static Public Attributes inherited from AutoForm
static $fieldRendererMap
 Provides the mapping from Type identifier to FieldRenderer. More...
 

Detailed Description

SearchForm generates forms for searching based on a supplied DataItem.

Since SearchForm extends AutoForm, functionality such as alias, hide, layout and field grouping, and custom field renderer are available.

Example to create the search form:

$order = new Order(); $order->filter = new InclusionFilter("order_date", "first_name, "last_name);

// on submit, system redirects to "review_orders" identifier and retrives // values through GET $form = new SearchForm($order, "GET", "review_orders");

// default matching mode is equal but can be set to others available // in the SearchParameters $form->setMatchingMode("startsWith", "first_name", "last_name"); $form->setMatchingMode("range", "order_date");

$script .= $form->writeScript(); $form->drawForm();


Example of the page that processes the constraint:

$order = new Order(); $order->filter = new InclusionFilter("order_date", "first_name, "last_name);

// on submit, system redirects to "review_orders" identifier and retrives // values through GET $search = new SearchParameters($order); $search->fromGET();

$constraint = $search->generateConstraint();


Example of drawing a readonly SearchForm on the results page to show the user the criteria on which they searched.

$order = new Order(); $order->filter = new InclusionFilter("order_date", "first_name, "last_name); $form = new SearchForm($order, "GET", "review_orders"); $form->readOnlyForm = true; $form->button("Search Again", "order_search_form");

$script .= $form->writeScript(); $form->drawForm();

Author
andy

Definition at line 1073 of file search_form.inc.

Member Function Documentation

◆ addDefaultValidators()

SearchForm::addDefaultValidators ( )

Creates default validators for fields in the form.

Currently this adds Date format validators to all date fields - other fields are not affected.

This method is called automatically before the form is rendered.

Reimplemented from AutoForm.

Definition at line 1267 of file search_form.inc.

1268  {
1269  $filter = $this->data->getFilter();
1270 
1271  foreach(array_keys($this->fields) as $field)
1272  {
1273  if ($filter && $filter->isExcluded($field)) continue;
1274  if ($this->readonly[$field]) continue; // No need to validate readonly fields
1275 
1276  $renderer = $this->getRenderer($field);
1277  if ($renderer)
1278  {
1279  // JDG 9/19/2010 - let each renderer supply its own validator
1280  $required = (array_search($field, $this->required) === FALSE) ? false : true;
1281  $mode = $this->getMatchingMode($field);
1282  $renderer->addSearchValidatorsToForm($field, $mode, $required);
1283  }
1284  }
1285 
1286  foreach($this->additional as $r)
1287  {
1288  // JDG 5/2012 - check if additional field is required
1289  $required = (array_search($r['field'], $this->required) === FALSE) ? false : true;
1290  $mode = $this->getMatchingMode($field);
1291  $r['renderer']->addSearchValidatorsToForm($r['field'], $mode, $required);
1292  }
1293  }
readonly()
Call this method to make one or more fields read-only in the form's user interface.
Definition: auto_form.inc:910
required()
Call this method to mark one or more fields as being required fields.
Definition: auto_form.inc:933
getRenderer($field)
Retrieves the FieldRenderer object for the specified field.
Definition: auto_form.inc:512
$required
List of required fields.
Definition: auto_form.inc:106
getMatchingMode($field)
Retrieve the matching mode that was set for the specified field.

◆ drawForm()

SearchForm::drawForm ( )

Write out the HTML for the search form.

See also
framework/AutoFormdrawForm()

Reimplemented from AutoForm.

Reimplemented in FilterForm.

Definition at line 1330 of file search_form.inc.

1331  {
1332  if ($this->readOnlyForm) return $this->drawReadOnly();
1333 
1334  $obj =& $this->data;
1335  $pk = $obj->primary_key;
1336 
1337  if ($this->preserveQueryString)
1338  {
1339  $obj->fromREQUEST();
1340  }
1341 
1343  if ($submitLabel == "")
1344  {
1345  $submitLabel = "Search ".pluralize($obj->prettifyClassName(true));
1346  }
1347 
1348  if (!$this->subordinate)
1349  {
1350  echo "<form id='{$this->id}' method='{$this->method}' action='{$this->action}' enctype='multipart/form-data'";
1351  if (!$this->ajaxSubmitHandler) echo " onsubmit='return onSubmit{$this->id}(this);'";
1352  echo ">\n";
1353  }
1354 
1355  if ($this->id)
1356  {
1357  echo "<input type='hidden' name='#FORMID#' value='{$this->id}'/>";
1358  }
1359 
1360  foreach(array_keys($this->hidden) as $hidden)
1361  {
1362  echo "<input id='{$hidden}' type='hidden' name='$hidden' value='".htmlSafe($obj->get($hidden))."'/>\n";
1363  }
1364 
1365  if ($this->preserveQueryString)
1366  {
1367  foreach($_GET as $key => $value)
1368  {
1369  if ($key == "identifier" || $key == "section" || $key == "submit" || array_key_exists($this->hidden, $key) || $obj->hasField($key)) continue;
1370  echo "<input id='{$this->id}_{$key}' type='hidden' name='$key' value='".htmlSafe($value)."'/>\n";
1371  }
1372  }
1373 
1374 
1375  $this->layout->startUngrouped();
1376 
1377  if ($this->buttons_at_top && !$this->subordinate)
1378  {
1379  $this->layout->startButtonLine();
1380 
1381  $this->drawSubmitButtons($obj, $pk, $submitLabel);
1382 
1383  $this->drawButtons();
1384 
1385  $this->layout->endButtonLine();
1386  }
1387 
1388  $this->layout->errorBox();
1389 
1390  if ($this->markRequiredFields && $this->validator->hasRequiredFields())
1391  {
1392  $this->layout->requiredFields($this->requiredFieldsText);
1393  }
1394 
1395  $this->renderSearchFields();
1396 
1397  if (!$this->subordinate)
1398  {
1399  $this->layout->startButtonLine();
1400 
1401  $this->drawSubmitButtons($obj, $pk, $submitLabel);
1402  $this->drawButtons();
1403 
1404  $this->layout->endButtonLine();
1405  }
1406 
1407  $this->layout->endUngrouped();
1408 
1409  if (!$this->subordinate)
1410  {
1411  echo "</form>\n";
1412  }
1413  }
drawButtons()
Draws any additional buttons specified in the calling script.
Definition: auto_form.inc:1459
$hidden
The hidden fields collection.
Definition: auto_form.inc:72
$submitLabel
Text to display on the form's submit button. If not specified defaut text will be generated based on ...
Definition: auto_form.inc:62
drawSubmitButtons($obj, $pk, $submitLabel)
Definition: auto_form.inc:1306
drawReadOnly()
Draws the form in read-only mode.

◆ drawReadOnly()

SearchForm::drawReadOnly ( )

Draws the form in read-only mode.

Used to display the search criteria on the results screen.

Reimplemented from AutoForm.

Definition at line 1555 of file search_form.inc.

1556  {
1557  echo "<table";
1558  if ($this->formCSS) echo " class='{$this->formCSS}'";
1559  if ($this->style) echo " style='{$this->style}'";
1560  echo ">\n";
1561 
1562  $obj =& $this->data;
1563  $pk = $obj->primary_key;
1564  $filter = $obj->getFilter();
1565 
1566  foreach($this->params->params as $param => $value)
1567  {
1568  list($field, $modifier) = explode(":", $param);
1569  if(!array_key_exists($field, $this->modifiers))
1570  $this->setMatchingMode($modifier, $field);
1571  }
1572 
1573  if (count($this->groups) > 0)
1574  {
1575  foreach($this->groups as $legend => $fields)
1576  {
1577  foreach($fields as $field)
1578  {
1579  if ($field != $pk && !array_key_exists($field, $this->hidden) &&
1580  !array_key_exists($field, $this->renderedFields) &&
1581  !($filter && $filter->isExcluded($field)))
1582  {
1583  $this->renderOneSearchField($field);
1584  }
1585  }
1586  }
1587  }
1588 
1589  foreach(array_keys($this->fields) as $field)
1590  {
1591  if ($field != $pk && !array_key_exists($field, $this->hidden) && !array_key_exists($field, $this->renderedFields) && !($filter && $filter->isExcluded($field)))
1592  {
1593  $this->renderOneSearchField($field);
1594  }
1595  }
1596 
1597  foreach($this->additional as $r)
1598  {
1599  $renderer = $r['renderer'];
1600  $field = $r['field'];
1601  if(!$field)
1602  $field = $renderer->field;
1603  if (!array_key_exists($field, $this->renderedFields) && !($filter && $filter->isExcluded($field)))
1604  {
1605  $this->renderOneSearchField($field);
1606  }
1607  }
1608 
1609  if(!$this->hasSearchCriteria)
1610  {
1611  echo "<tr>\n<td style='padding-top: 10px; padding-bottom: 10px'><i>{$this->emptyMessage}</i></td>\n</tr>\n";
1612  }
1613 
1614  ob_start();
1615  $this->drawButtons();
1616  $buttons .= ob_get_contents();
1617  ob_end_clean();
1618 
1619  if($buttons)
1620  echo "<tr><td>". preg_replace("/^(&nbsp;)+/", "", $buttons) . "</td>\n<tr>\n";
1621 
1622  echo "</table>";
1623  }
$fields
Local field cache.
Definition: auto_form.inc:111
$buttons
The custom buttons collection.
Definition: auto_form.inc:77
renderOneSearchField($field)
setMatchingMode($mode)
Sets the matching mode for the specified fields.

◆ getMatchingMode()

SearchForm::getMatchingMode (   $field)

Retrieve the matching mode that was set for the specified field.

Parameters
string$fieldthe field to query
Returns
string the matching mode set for that field.

Definition at line 1121 of file search_form.inc.

1122  {
1123  $mode = (array_key_exists($field, $this->modifiers)) ? $this->modifiers[$field] : "equal";
1124  return $mode;
1125  }

◆ populateFromGET()

SearchForm::populateFromGET ( )

Populate the search parameters from an HTTP GET request.

Definition at line 1130 of file search_form.inc.

1131  {
1132  $this->params->fromGET();
1133  }

◆ populateFromPOST()

SearchForm::populateFromPOST ( )

Populate the search parameters from an HTTP POST request.

Definition at line 1138 of file search_form.inc.

1139  {
1140  $this->params->fromPOST();
1141  }

◆ populateFromREQUEST()

SearchForm::populateFromREQUEST ( )

Definition at line 1143 of file search_form.inc.

1144  {
1145  $this->params->fromArray($_REQUEST);
1146  }

◆ renderAdditionalFields()

SearchForm::renderAdditionalFields (   $obj)

Reimplemented from AutoForm.

Definition at line 1532 of file search_form.inc.

1533  {
1534  foreach($this->additional as $r)
1535  {
1536  $renderer = $r['renderer'];
1537  $field = $r['field'];
1538  if(!$field)
1539  $field = $renderer->field;
1540 
1541  $mode = $this->getMatchingMode($field);
1542 
1543  if(!array_key_exists($field, $this->renderedFields))
1544  {
1545  $renderer->renderSearchField($field, $mode);
1546  }
1547  $this->renderedFields[$field] = true;
1548  }
1549  }

◆ renderOneSearchField()

SearchForm::renderOneSearchField (   $field)

Definition at line 1482 of file search_form.inc.

1483  {
1484  $mode = $this->getMatchingMode($field);
1485  $renderer = $this->getRenderer($field);
1486 
1487  if(!$renderer && !$this->data->hasField($field) && $this->data->getType($field) != "Timestamp")
1488  {
1489  foreach($this->additional as $r)
1490  {
1491  $renderer = $r['renderer'];
1492  $field = $r['field'];
1493  if(!$field)
1494  $field = $renderer->field;
1495  }
1496  }
1497 
1498  if ($renderer)
1499  {
1500  if(!$this->readOnlyForm)
1501  {
1502  $renderer->renderSearchField($field, $mode);
1503  }
1504  else if($this->readOnlyForm && (get_class($renderer) != DateFieldRenderer || $mode != "range"))
1505  {
1506  $value = $this->params->get($field, $mode);
1507  if($value)
1508  {
1509  // Set the value into the form's data obj so that the
1510  // renderReadOnly function works the same as with AutoForm
1511  $this->data->set($field, $value);
1512  $renderer->renderReadOnly($field);
1513  $this->hasSearchCriteria = true;
1514  }
1515  }
1516  else if($this->readOnlyForm)
1517  {
1518  $date_from = $this->params->get($field, "from");
1519  $date_to = $this->params->get($field, "to");
1520  if($date_from || $date_to)
1521  {
1522  $renderer->renderDateRangeReadOnly($field, $date_from, $date_to);
1523  $this->hasSearchCriteria = true;
1524  }
1525  }
1526  // count as rendered even if we didn't render because readonly and
1527  // no value so that we don't try to render again
1528  $this->renderedFields[$field] = true;
1529  }
1530  }
Field renderer for date data fields.

◆ renderSearchFields()

SearchForm::renderSearchFields ( )

Reimplemented in FilterForm.

Definition at line 1415 of file search_form.inc.

1416  {
1417  $obj =& $this->data;
1418  $filter = $obj->getFilter();
1419 
1420  if (count($this->groups) > 0)
1421  {
1422  $this->layout->endUngrouped();
1423 
1424  foreach($this->groups as $legend => $fields)
1425  {
1426  $collapsible = array_key_exists($legend, $this->collapsibleGroups);
1427  if ($collapsible)
1428  {
1429  $cf = $this->collapsibleGroups[$legend];
1430  $collapsed = !$this->data->$cf;
1431  }
1432 
1433  $this->layout->startGroup($legend, $collapsible, $collapsed);
1434 
1435  foreach($fields as $field)
1436  {
1437  if ($field != $pk && !array_key_exists($field, $this->hidden) && !array_key_exists($field, $this->renderedFields) &&
1438  ($this->hasAdditional($field) || !($filter && $filter->isExcluded($field))))
1439  {
1440  $this->renderOneSearchField($field);
1441  }
1442  }
1443 
1444  $this->layout->endGroup();
1445  }
1446 
1447  $this->layout->startUngrouped();
1448 
1449  }
1450 
1451  foreach(array_keys($this->fields) as $field)
1452  {
1453  if ($field != $pk && !array_key_exists($field, $this->hidden) && !array_key_exists($field, $this->renderedFields) &&
1454  ($this->hasAdditional($field) || !($filter && $filter->isExcluded($field))))
1455  {
1456  $this->renderOneSearchField($field);
1457  }
1458  }
1459 
1460  foreach($this->additional as $r)
1461  {
1462  $renderer = $r['renderer'];
1463  $field = $r['field'];
1464  if(!$field)
1465  $field = $renderer->field;
1466 
1467  trace("Rendering additional field $field", 3);
1468 
1469  if (!array_key_exists($field, $this->renderedFields))
1470  {
1471  $this->renderOneSearchField($field);
1472  }
1473  }
1474  }
hasAdditional($field)
Check if this field exists as an additional field.
Definition: auto_form.inc:947
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ SearchForm()

SearchForm::SearchForm (   $target,
  $method = "POST",
  $action = "",
  $id = "" 
)

Create a new Search Form.

Parameters
DataItem$targetthe target DataItem object
string$method(optional) the HTTP method to use for submitting the search request
string$action(optional) the URL of the recipient script for the search request
string$id(optional) the DOM ID for the generated search form
Returns
SearchForm

Definition at line 1092 of file search_form.inc.

1093  {
1094  $this->AutoForm($target, $method, $action, $id);
1095  $this->modifiers = array();
1096  $this->params = new SearchParameters($target, $this);
1097 
1098  $this->validator = new ValidationEngine();
1099  $this->validator->id = $this->id;
1100  }
AutoForm($target, $method="POST", $action="", $id="")
Creates a new AutoForm, based on the supplied target DataItem.
Definition: auto_form.inc:166
$action
Action URL for submitting the form. Generally this can be left blank to submit back to the same page.
Definition: auto_form.inc:68
$method
HTTP method that will be used to submit the form.
Definition: auto_form.inc:67
The SearchParameters class interprets the set of input parameters for a search and generates the corr...
The ValidationEngine takes an array of validator objects in its constructor, and is then able to gene...

◆ setHandler()

SearchForm::setHandler (   $field,
  $handler 
)

Override an existing SearchParameter constraint clause handler or add one.

Parameters
$fieldstring name of the field
$handlercallable callback function that creates the constraint clause for the given field

Reimplemented in FilterForm.

Definition at line 1156 of file search_form.inc.

1157  {
1158  $this->params->paramHandlers[$field] = $handler;
1159  }

◆ setMatchingMode()

SearchForm::setMatchingMode (   $mode)

Sets the matching mode for the specified fields.

Parameters
string$modethe matching mode, which can be one of "equal", "like", "startsWith", "from" or "to"

Definition at line 1106 of file search_form.inc.

1107  {
1108  $fields = func_get_args();
1109  for($i = 1; $i < count($fields); ++$i)
1110  {
1111  $this->modifiers[$fields[$i]] = $mode;
1112  }
1113 
1114  }

◆ setSearchValidator()

SearchForm::setSearchValidator (   $renderer,
  $field,
  $mode 
)

After AutoForm configures the validators, modify the field name to include the mode with which the tag will drawn in the form.

For date range, the mode is "from" and an additional validator needs to be created for the "to" field.

Parameters
obj$renderer- field renderer
String$field- field name
String$mode- matching mode

Definition at line 1306 of file search_form.inc.

1307  {
1308  foreach($this->validator->validators as $v)
1309  {
1310  if($v->field != $field) continue;
1311  if($mode != "range")
1312  {
1313  $v->field = "{$v->field}:{$mode}";
1314  }
1315  else
1316  {
1317  $v->field = "{$v->field}:from";
1318  $toLabel = preg_replace("/between|to/i", "To", $v->title);
1319  $toV = new DateValidator("{$field}:to", $toLabel);
1320  $this->validator->add($toV);
1321  }
1322  }
1323  }
Date Validator.
Definition: validation.inc:338

◆ writeScript()

SearchForm::writeScript ( )

Generate any javascript required by the search form.

See also
framework/AutoFormwriteScript()

Reimplemented from AutoForm.

Reimplemented in FilterForm.

Definition at line 1165 of file search_form.inc.

1166  {
1167  ob_start();
1168 
1169  $this->configureValidators();
1170 
1171  $obj =& $this->data;
1172  $script = "";
1173  foreach(array_keys($obj->getFields()) as $field)
1174  {
1175  trace("SearchForm writeScript field $field", 3);
1176  if ($field != $pk&&
1177  !($obj->filter && $obj->filter->isExcluded($field)))
1178  {
1179  $mode = $this->getMatchingMode($field);
1180 
1181  $renderer = $this->getRenderer($field);
1182  if ($renderer)
1183  {
1184  $renderer->renderSearchScript($field, $mode);
1185  }
1186  }
1187  }
1188 
1189  // JDG 7/15/2011 - need scripts for additional fields
1190  foreach($this->additional as $r)
1191  {
1192  $renderer = $r['renderer'];
1193  $field = $r['field'];
1194  if(!$field)
1195  $field = $renderer->field;
1196 
1197  $mode = $this->getMatchingMode($field);
1198  $renderer->renderSearchScript($field, $mode);
1199  }
1200 
1201  echo "<script type='text/javascript'>\n";
1202  echo $this->validator->writeScript();
1203  echo "\n\n";
1204  echo "function onSubmit{$this->id}(form)\n{\n";
1205 
1206  echo "\tif (validate_{$this->id} != null && !validate_{$this->id}(form)) return false;\n";
1207 
1208 
1209  foreach(array_keys($this->fields) as $field)
1210  {
1211  if ($field != $pk && !($filter && $filter->isExcluded($field)))
1212  {
1213  $renderer = $this->getRenderer($field);
1214  if ($renderer)
1215  {
1216  $renderer->renderOnSubmitHandler($field);
1217  }
1218  }
1219  }
1220 
1221  foreach($this->additional as $r)
1222  {
1223  $r['renderer']->renderOnSubmitHandler($r['field']);
1224  }
1225 
1226  if ($this->onSubmitHandler)
1227  {
1228  echo "\t if (!{$this->onSubmitHandler}(form)) return false;\n;";
1229  }
1230 
1231  if ($this->interstitialMessage)
1232  {
1233  echo "\tinterstitial('".jsSafe($this->interstitialMessage)."');\n;";
1234  }
1235 
1236  echo "\treturn true;\n}\n\n";
1237 
1238 
1239  echo "\twindow.addEvent('domready', function() {\n";
1240 
1241  if ($this->allowPartialSave)
1242  {
1243  $managerOptions = "{partialSaveContainer: '{$this->partialSaveContainerID}', partialSaveLabel: '{$this->partialSaveLabel}'}";
1244  }
1245  else
1246  {
1247  $managerOptions = "{}";
1248  }
1249 
1250  echo "\tnew AutoFormManager('{$this->id}', {$managerOptions});\n";
1251  echo "});\n";
1252 
1253  echo "</script>\n";
1254 
1255  $script = ob_get_contents();
1256  ob_end_clean();
1257  return $script;
1258  }
configureValidators()
Definition: auto_form.inc:353

Member Data Documentation

◆ $emptyMessage

SearchForm::$emptyMessage = "No search criteria was provided."

Definition at line 1078 of file search_form.inc.

◆ $hasSearchCriteria

SearchForm::$hasSearchCriteria = false

Definition at line 1077 of file search_form.inc.

◆ $modifiers

SearchForm::$modifiers

Definition at line 1075 of file search_form.inc.

◆ $params

SearchForm::$params

Definition at line 1076 of file search_form.inc.

◆ $preserveQueryString

SearchForm::$preserveQueryString = false

Definition at line 1079 of file search_form.inc.

◆ $searchModeTypes

SearchForm::$searchModeTypes
Initial value:
= array("like" => "exact phrase match",
"all" => "match all words in any order",
"any" => "match any words")

Definition at line 1081 of file search_form.inc.


The documentation for this class was generated from the following file: