Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Add captcha on the last page.
- */
- /**
- * Set captcha on the last page in webform.
- */
- function custom_node_create_node_insert($node) {
- if ($node->type == 'product_review') {
- $body = field_get_items('node', $node, 'body');
- $comp = explode("\n", $body[0]['value']);
- $components = array();
- foreach ($comp as $c) {
- if ($c == '') {
- // Skip empty lines. Maybe the non-tech admin pressed an extra enter?
- continue;
- }
- // Create the webform components array. Not sure if we need all these
- // values, but let's be sure.
- $components = array(
- array(
- 'name' => 'body',
- 'form_key' => 'body',
- 'type' => 'markup',
- 'title' => t('Body'),
- 'value' => $node->body['und'][0]['value'],
- 'mandatory' => 1,
- 'weight' => 5,
- 'pid' => 0,
- 'extra' => array(
- 'title_display' => 'inline',
- 'private' => 0,
- ),
- ),
- array(
- 'name' => 'Product references',
- 'form_key' => 'product_references',
- 'type' => 'markup',
- 'title' => t('Product references'),
- 'value' => $node->field_product_references['und'][0]['nid'],
- 'mandatory' => 1,
- 'weight' => 6,
- 'pid' => 0,
- 'extra' => array(
- 'title_display' => 'inline',
- 'private' => 0,
- ),
- ),
- );
- }
- // Alright, let's create the node object.
- $n = new stdClass();
- $n->type = 'webform';
- // Let the user be the author.
- $n->uid = $node->uid;
- // Let the 'order' title be the webform title.
- $n->title = $node->title;
- // I put them all on the frontpage.
- $n->promote = 1;
- // And we are allowed to comment.
- $n->comment = 2;
- $emails = array(
- array(
- 'email' => 'somebody@example.tld',
- 'subject' => 'default',
- 'from_name' => 'default',
- 'from_address' => 'default',
- 'template' => 'default',
- 'excluded_components' => array(),
- ),
- );
- // Enter webform array.
- $n->webform = array(
- 'confirmation' => '',
- 'confirmation_format' => NULL,
- 'redirect_url' => '<confirmation>',
- 'status' => '1',
- 'block' => '0',
- 'teaser' => '0',
- 'allow_draft' => '0',
- 'auto_save' => '0',
- 'record_exists' => TRUE,
- 'emails' => $emails,
- // Here comes our $components array.
- 'components' => $components,
- );
- // Save the node.
- node_save($n);
- // You could also put something like drupal_goto('node/' . $n->nid) here if
- // you want. My use case is different.
- }
- if ($node->type == 'webform') {
- $sids = db_select('webform_submissions', 'ws')
- ->fields('ws', array('sid'))
- ->execute()->fetchAll();
- foreach ($sids as $result) {
- $sid[] = $result->sid;
- }
- global $user;
- $sid_for_insert = end($sid) + 1;
- $id = db_insert('webform_submissions')
- ->fields(array('sid' => $sid_for_insert, 'nid' => $node->nid, 'serial' => $sid_for_insert, 'uid' => $user->uid, 'is_draft' => 0, 'submitted' => time()))
- ->execute();
- }
- //drupal_mail('custom_node_create', 1, 'somebody@example.tld', 'en', $params = array('$components'), $from = NULL, $send = TRUE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement