5 * Test module implementing a form that can be embedded in search results.
7 * Embedded form are important, for example, for ecommerce sites where each
8 * search result may included an embedded form with buttons like "Add to cart"
9 * for each individual product (node) listed in the search results.
13 * Implements hook_menu().
15 function search_embedded_form_menu() {
16 $items['search_embedded_form'] = array(
17 'title' => 'Search_Embed_Form',
18 'page callback' => 'drupal_get_form',
19 'page arguments' => array('search_embedded_form_form'),
20 'access arguments' => array('search content'),
21 'type' => MENU_CALLBACK,
28 * Builds a form for embedding in search results for testing.
30 * @see search_embedded_form_form_submit().
32 function search_embedded_form_form($form, &$form_state) {
33 $count = variable_get('search_embedded_form_submitted', 0);
35 $form['name'] = array(
36 '#type' => 'textfield',
37 '#title' => t('Your name'),
39 '#default_value' => '',
41 '#description' => t('Times form has been submitted: %count', array('%count' => $count)),
44 $form['actions'] = array('#type' => 'actions');
45 $form['actions']['submit'] = array(
47 '#value' => t('Send away'),
50 $form['#submit'][] = 'search_embedded_form_form_submit';
56 * Submit handler for search_embedded_form_form().
58 function search_embedded_form_form_submit($form, &$form_state) {
59 $count = variable_get('search_embedded_form_submitted', 0) + 1;
60 variable_set('search_embedded_form_submitted', $count);
61 drupal_set_message(t('Test form was submitted'));
65 * Adds the test form to search results.
67 function search_embedded_form_preprocess_search_result(&$variables) {
68 $form = drupal_get_form('search_embedded_form_form');
69 $variables['snippet'] .= drupal_render($form);