test ecclesia autocomplete
This commit is contained in:
@@ -321,6 +321,14 @@ function booking_menu() {
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
//callback for autocomplete lookup of ecclesia name
|
||||
$items['booking/ecclesia/autocomplete'] = array(
|
||||
'title' => 'Autocomplete for ecclesia lookup on registration page',
|
||||
'page callback' => '_booking_ecclesia_name_autocomplete',
|
||||
'access arguments' => array('access booking form'),
|
||||
'type' => MENU_CALLBACK
|
||||
);
|
||||
|
||||
$items['waitinglist'] = array(
|
||||
'title' => "Who's on the waiting list?",
|
||||
'page callback' => 'booking_waitinglist_page',
|
||||
|
@@ -63,6 +63,31 @@ function booking_register_page()
|
||||
return $return_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* autocomplete helper to look up ecclesia names
|
||||
* based on https://www.drupal.org/node/854216
|
||||
* $string = string for search
|
||||
*/
|
||||
function _booking_ecclesia_name_autocomplete($string) {
|
||||
$matches = array();
|
||||
$sanitised_string = preg_replace("/[^a-zA-Z0-9\s\.']/", '', $string);
|
||||
$sanitised_string += "%";
|
||||
watchdog('booking_debug', "<pre>Autocomplete checking for ecclesia matching:\n@info</pre>", array('@info' => print_r($sanitised_string, true)));
|
||||
|
||||
$query = db_select('booking_person', 'p')
|
||||
->fields('p', array('booking_ecclesia'))
|
||||
->condition('p.booking_ecclesia', $sanitised_string, 'LIKE');
|
||||
$result = $query->execute();
|
||||
|
||||
// save the query to matches
|
||||
foreach ($result as $row) {
|
||||
$matches[$row->booking_ecclesia] = $row->booking_ecclesia;
|
||||
}
|
||||
|
||||
// Return the result to the form in json
|
||||
drupal_json_output($matches);
|
||||
}
|
||||
|
||||
function booking_form($node, &$form_state, $inserting = FALSE)
|
||||
{
|
||||
global $event;
|
||||
@@ -289,14 +314,26 @@ function booking_form($node, &$form_state, $inserting = FALSE)
|
||||
'#options' => _get_tshirt_options()
|
||||
);
|
||||
} //end enable tshirts check
|
||||
|
||||
$form['your-details']['booking_ecclesia'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Ecclesia'),
|
||||
'#maxlength' => 100,
|
||||
'#required' => FALSE,
|
||||
'#default_value' => !empty($data->booking_ecclesia) ? $data->booking_ecclesia : ''
|
||||
);
|
||||
|
||||
if ($inserting == FALSE) {
|
||||
$form['your-details']['booking_ecclesia'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Ecclesia'),
|
||||
'#size' => 100,
|
||||
'#autocomplete_path' => 'booking/ecclesia/autocomplete',
|
||||
'#value' => !empty($data->booking_ecclesia) ? $data->booking_ecclesia : '',
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['your-details']['booking_ecclesia'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Ecclesia'),
|
||||
'#maxlength' => 100,
|
||||
'#required' => FALSE,
|
||||
'#default_value' => !empty($data->booking_ecclesia) ? $data->booking_ecclesia : '',
|
||||
);
|
||||
}
|
||||
|
||||
$form['your-details']['booking_baptised'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('I am baptised'),
|
||||
|
Reference in New Issue
Block a user