Skip to content

Instantly share code, notes, and snippets.

@mavimo
Created April 11, 2012 17:17
Show Gist options
  • Save mavimo/2360658 to your computer and use it in GitHub Desktop.
Save mavimo/2360658 to your computer and use it in GitHub Desktop.
Add webform
<?php
// Create webform default element
if (!isset($node->webform)) {
$node->webform = webform_node_defaults();
}
// @todo: remove unused settings
$node->webform['confirmation'] = 'BLA BLA BLA';
$node->webform['confirmation_format'] = 'full_html';
$node->webform['redirect_url'] = '<confirmation>';
$node->webform['status'] = 1;
$node->webform['block'] = 0;
$node->webform['teaser'] = 0;
$node->webform['allow_draft'] = 0;
$node->webform['auto_save'] = 0;
$node->webform['submit_notice'] = 0;
$node->webform['submit_text'] = 'Invia richiesta';
$node->webform['submit_limit'] = -1;
$node->webform['submit_interval'] = -1;
$node->webform['record_exist'] = 1;
// @todo: we can remove it, already set by webform
$node->webform['roles'] = array(
0 => 1,
1 => 2,
);
$node->webform['emails'] = array(
1 => array(
'eid' => 1,
'email' => '[email protected]',
'subject' => 'Messaggio di conferma',
'from_name' => 'default',
'from_address' => 'default',
'template' => 'default',
'excluded_components' => array(),
'html' => 0,
'attachments' => 0,
),
);
// Description
$node->webform['components'][] = array(
'cid' => 1,
'pid' => 0,
'form_key' => 'description',
'name' => 'Description',
'type' => 'markup',
'value' => 'Contattaci ora per ricevere informazioni',
'weight' => 0,
'extra' => array(
'format' => 'plain_text',
),
);
// First name
$node->webform['components'][] = array(
'cid' => 2,
'pid' => 0,
'form_key' => 'nome',
'name' => 'Nome',
'type' => 'textfield',
'mandatory' => 1,
'weight' => 1,
'extra' => array(
'width' => 40,
),
);
// Last name
$node->webform['components'][] = array(
'cid' => 3,
'pid' => 0,
'form_key' => 'cognome',
'name' => 'Cognome',
'type' => 'textfield',
'mandatory' => 1,
'weight' => 2,
'extra' => array(
'width' => 40,
),
);
// Mail
$node->webform['components'][] = array(
'cid' => 4,
'pid' => 0,
'form_key' => 'email',
'name' => 'Email',
'type' => 'email',
'mandatory' => 1,
'weight' => 3,
'extra' => array(
'width' => 40,
),
);
// Phone
$node->webform['components'][] = array(
'cid' => 5,
'pid' => 0,
'form_key' => 'phone',
'name' => 'Telefono',
'type' => 'textfield',
'mandatory' => 0,
'weight' => 4,
'extra' => array(
'width' => 40,
),
);
// Settore
$node->webform['components'][] = array(
'cid' => 6,
'pid' => 0,
'form_key' => 'field',
'name' => 'Settore',
'type' => 'textfield',
'mandatory' => 0,
'weight' => 5,
'extra' => array(
'width' => 40,
),
);
// Azienda
$node->webform['components'][] = array(
'cid' => 7,
'pid' => 0,
'form_key' => 'company',
'name' => 'Azienda',
'type' => 'textfield',
'mandatory' => 0,
'weight' => 6,
'extra' => array(
'width' => 40,
),
);
// Request
$node->webform['components'][] = array(
'cid' => 8,
'pid' => 0,
'form_key' => 'request',
'name' => 'Richiesta',
'type' => 'textarea',
'mandatory' => 0,
'weight' => 7,
);
// Privacy
$node->webform['components'][] = array(
'cid' => 9,
'pid' => 0,
'form_key' => 'privacy',
'name' => 'Privacy',
'type' => 'select',
'mandatory' => 1,
'weight' => 8,
'extra' => array(
'multiple' => 1,
'title_display' => 'none',
'items' => 'accept|Dichiaro di aver letto e accettato l\'<a href="/privacy-policy">informativa sulla privacy*</a>',
),
);
// Informativa pubblicitaria
$node->webform['components'][] = array(
'cid' => 10,
'pid' => 0,
'form_key' => 'informativa_pubblicitaria',
'name' => 'Informativa pubblicitaria',
'type' => 'select',
'mandatory' => 1,
'weight' => 9,
'extra' => array(
'multiple' => 1,
'title_display' => 'none',
'items' => 'accept|Presto il consenso alla <a href="/trattamento-dati">trasmissione dei dati</a>',
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment