This is sort of hacky but I couldn't figure out a way to do it with Webforms natively. This implementation uses a custom module.
// Register custom module block
function my_module_block_info() {
$blocks = array();
$blocks['my_form'] = array(
'info' => t('My Form Title'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
// set block content
function download_training_plan_block_view($delta) {
$block = array();
switch ($delta) {
case 'my_form':
$block['subject'] = '';
$block['content'] = my_form_details();
break;
}
return $block;
}
// set block theme
function my_form_details() {
return theme('my_form_details');
}
// use custom template file.
function download_training_plan_theme() {
$template_path = drupal_get_path('module', 'my_module_template_file') . '/templates';
$theme_hooks = array(
'my_form_details' => array(
'path' => $template_path,
'template' => 'Altered form',
'variables' => array('title' => NULL),
),
);
return $theme_hooks;
}
// when webform is used, alter form to include callback function
function my_module_form_alter(&$form, &$form_state, $form_id) {
if ($form['#node']->title == 'Obstacle Teaser 2018 Data Capture'){
$form['actions']['submit'] = array(
'#type' => 'submit',
'#ajax' => array(
'callback' => 'my_form_callback',
'wrapper' => str_replace('_', '-', $form['#form_id']),
),
'#value' => t('Submit'),
);
}
}
// set cookie to remember submitted state and show hidden content
function my_form_callback(&$form, &$form_state) {
if (!form_get_errors() && $form_state['values']['details']['sid']) {
// Save cookie.
setcookie('is_submitted_cookie', TRUE, REQUEST_TIME + (31556926 * 2), '/');
$commands = array();
$commands[] = ajax_command_invoke('#secret_content', 'show'); //show hidden content
return array('#type' => 'ajax', '#commands' => $commands);
}
return $form;
}
// in file: my_module_template_file.tpl.php
<?php $download_form = module_invoke('webform', 'block_view', 'client-block-999999'); ?> // replace 999999 with nodeID of webform.
<?php if (!empty($download_form['content'])): ?>
<?php print render($download_form['content']); ?>
<?php endif; ?>
<div id="secret_content" style="display:none;"><a href="#">Download content</a></div>