Skip to content

Instantly share code, notes, and snippets.

@matglas
Last active December 23, 2015 10:28
Show Gist options
  • Save matglas/6621394 to your computer and use it in GitHub Desktop.
Save matglas/6621394 to your computer and use it in GitHub Desktop.
Dynamicly add a webform.
<?php
/**
* Implements hook_install().
*/
function hook_install() {
// Create Contact form from data file
// Define your components.
// Use dpm() on node_view to see the definition for other components.
$components = array(
array(
'name' => 'Name',
'form_key' => 'name_key',
'type' => 'select',
'mandatory' => 1,
'weight' => 1,
'pid' => 0,
'extra' => array(
'title_display'=>'inline',
'private'=>0,
'items'=>"",
'aslist'=>0
)
),
);
$form = new stdClass();
$form->body[LANGUAGE_NONE][0]['value'] = '<p></p>';
$form->body[LANGUAGE_NONE][0]['format'] = 'format_name';
$form->webform = array(
'confirmation' => ' <p>Tekst</p>',
'confirmation_format' => 'format_name',
'redirect_url' => '<none>',
'status' => '1',
'block' => '0',
'teaser' => '0',
'allow_draft' => '0',
'auto_save' => '0',
'submit_notice' => '1',
'submit_text' => '',
'submit_limit' => '-1', // User can submit more than once.
'submit_interval' => '-1',
'total_submit_limit' => '-1',
'total_submit_interval' => '-1',
'record_exists' => TRUE,
'roles' => array(
0 => '1', // Anonymous user can submit this webform.
),
'emails' => array(),
'components' => $components
);
$requiredProperties = array(
'type' => 'webform',
'title' => 'Form name',
'language' => LANGUAGE_NONE,
'uid' => 1,
'status' => 1,
// Add a menu link to the contact page, all the way to the right of the main menu (weight 8)
'menu' => array(
'enabled' => 1,
'link_title' => 'Form name',
'menu_name' => 'main-menu',
'weight' => 8,
'description' => 'Form name',
),
);
$node = kw_itemnames_ensure(
'node',
$requiredProperties['title'],
$requiredProperties,
(array)$form
);
webform_ensure_record($node);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment