function google_cse_searchbox_formbuilder in Google Custom Search Engine 5
Form builder for the searchbox forms.
1 string reference to 'google_cse_searchbox_formbuilder'
- google_cse_forms in ./
google_cse.module - Implementation of hook_forms();
File
- ./
google_cse.module, line 216 - Display a Google Custom Search Engine on your site.
Code
function google_cse_searchbox_formbuilder($form_id) {
global $locale;
$form = array();
// The default form.
if (variable_get('google_cse_results_display', 'here') == 'here') {
$form['#action'] = url('search/google');
$q = 'query';
// parameter on Drupal site
$cof = 'FORID:11';
}
else {
$form['#action'] = 'http://www.google.com/cse';
$q = 'q';
// parameter on Google
$cof = 'FORID:0';
}
$form['#method'] = 'get';
$form['cx'] = array(
'#type' => 'hidden',
'#value' => variable_get('google_cse_cx', ''),
);
$form['cof'] = array(
'#type' => 'hidden',
'#value' => $cof,
);
$form[$q] = array(
'#type' => 'textfield',
'#default_value' => $_GET['query'],
);
$form['sa'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
foreach (google_cse_advanced_settings() as $parameter => $setting) {
$form[$parameter] = array(
'#type' => 'hidden',
'#value' => $setting,
);
}
drupal_add_css(drupal_get_path('module', 'google_cse') . '/google_cse.css');
drupal_add_js(array(
'googleCSE' => array(
'locale' => array(
$locale,
),
),
), 'setting', 'header');
drupal_add_js(drupal_get_path('module', 'google_cse') . '/google_cse.js', 'module', 'footer');
// And the small differences between both.
switch ($form_id) {
case 'searchbox':
$form[$q]['#size'] = intval(variable_get('google_cse_searchbox_width', 15));
$form[$q]['#attributes']['title'] = t('Enter the terms you wish to search for.');
break;
case 'results_searchbox':
$form[$q]['#size'] = intval(variable_get('google_cse_results_searchbox_width', 40));
$form[$q]['#title'] = t('Enter your keywords');
$form['sa']['#suffix'] = google_cse_results_gadget();
break;
}
return $form;
}