I am trying to make a custom form block in drupal. I want it to display my form, then after submitting, show the results. I have an if statement in the hook_block_view function saying if my form has been filled out to set $block['content'] to "Form Submitted". This doesn't work though, it just displays the form again. I have the same if statement in my hook_form_submitted function to either set drupal_set_message to either 'Submitted' or to display what was put into the form. After submitting, when the page reloads, The form still displays, $block['content'] does not get set, but drupal_set_message() does. What am I doing wrong?

Just thought of something, my block_view() only passes ($delta = '') is it just that $form_state['values'] is not being passed through the function?


 * @file

 * Implements hook_block_info().

 function search_engine_block_info() {
     $blocks = array();
     $blocks['search_engine'] = array(
        'info' => t('Search Engine'),
        'cache'=> DRUPAL_CACHE_GLOBAL,
    return $blocks;

 * Implements hook_block_view().

 function search_engine_block_view($delta = ''){
     $block = array();
     switch ($delta) {
     case 'search_engine':
         $block['subject'] = t('Search Engine');
         //Check to see if the form has been submitted.  If not, show form, or else show results.
            $block['content'] = drupal_get_form('search_engine_form');   
            $block['content'] = 'Form Submitted';    
     return $block;

 * Implements hook_form.

 function search_engine_form ($form, &$form_state){
    $form['searchOptions'] = array(
        '#type'     => 'select',
        '#title'    => t('You can search by GWF Number, name, email address or phone number.'),
        '#options'  => array(
            'gwf'           => t('GWF Number'),
            'applicant_email'   => t('Email Address'),
            'name'          => t('Name'),
            'phone_number'      => t('Phone Number'),
        '#value'    => 'gwf',
    $form['searchInput'] = array(
        '#type'     => 'textfield',
        '#title'    => t(''),
    $form['submit'] = array(
        '#type' => 'submit',
        '#value'=> t('Submit'),
    return $form;       

 * Implements hook_form_submit.

 function search_engine_form_submit($form, &$form_state){

1 Answer 1


$form_state['values']['searchInput'] is undefined in that function so this will never work. You could remove the if in this function and let search_engine_form return HTML if it is submitted. You can add it inside the if you're using for the message display.

You maybe have to use the #rebuild option on that form, so it gets rebuild.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.