View source
<?php
function webform_password_field_webform_component_info() {
$component = array();
$component['password'] = array(
'type' => 'textfield',
'label' => t('Password field'),
'description' => t('Basic password field'),
'features' => array(
'csv' => TRUE,
'email' => TRUE,
'email_address' => FALSE,
'email_name' => TRUE,
'required' => TRUE,
'conditional' => TRUE,
'group' => FALSE,
'attachment' => FALSE,
),
'file' => 'password.inc',
);
return $component;
}
function webform_password_field_webform_validation_validators() {
return array(
'password' => array(
'name' => "Compare password values",
'component_types' => array(
'password',
),
'min_components' => 2,
'max_components' => 2,
'description' => t('Verifies that two password field values are equal.'),
),
);
}
function webform_password_field_webform_validation_validate($validator_name, $items, $components, $rule) {
if ($items) {
switch ($validator_name) {
case 'password':
$errors = array();
$first_entry_key = key($items);
$first_entry = array_shift($items);
foreach ($items as $key => $val) {
if ($val !== $first_entry) {
$errors[$key] = t('%item_checked does not match %item_first.', array(
'%item_checked' => $components[$key]['name'],
'%item_first' => $components[$first_entry_key]['name'],
));
}
}
return $errors;
break;
}
}
}
function webform_password_field_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['type']['#value']) && $form['type']['#value'] == 'password') {
$form['wpf_placeholder'] = array(
'#type' => 'textfield',
'#title' => t('Placeholder'),
'#description' => t('Enter placeholder for your password field'),
'#default_value' => variable_get('wpf_placeholder', t('Password')),
);
}
if (strstr($form_id, 'webform_client_form')) {
if (in_array('password', $form)) {
$form_key = variable_get('wpf_form_key', t('Password'));
$form['submitted'][$form_key]['#attributes'] = array(
'placeholder' => variable_get('wpf_placeholder', t('Password')),
);
}
}
}
function webform_password_field_webform_component_insert($component) {
if ($component['type'] == 'password') {
$cid = $component['cid'];
$form_key = $component['form_key'];
variable_set('wpf_cid', $cid);
variable_set('wpf_form_key', $form_key);
}
}
function webform_password_field_webform_component_delete($component) {
variable_del('wpf_cid');
variable_del('wpf_form_key');
variable_del('wpf_placeholder');
}