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_messag
e 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?
<?php
/**
* @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.
if(!isset($form_state['values']['searchInput'])){
$block['content'] = drupal_get_form('search_engine_form');
}else{
$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){
if(isset($form_state['values']['submit'])){
drupal_set_message('Sumbmitted!!');
}else{
drupal_set_message($form_state['values']['searchOptions']);
}
}