1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| <?php
/**
* Implements hook_permission()
*/
function inscription_newsletter_permission() {
return array(
'submit inscription_newsletter' => array(
'title' => t('Submit inscription_newsletter'),
'description' => t('Submit the inscription_newsletter form'),
),
'access inscription_newsletter submission' => array(
'title' => t('Access inscription_newsletter submission'),
'description' => t('Accesse the inscription_newsletter submission'),
),
);
}
/**
* Implements hook_menu()
*/
function inscription_newsletter_menu() {
$items = array();
$items['inscription-newsletter'] = array(
'title' => 'Inscription Newsletter Formulaire',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('submit inscription_newsletter'),
'page callback' => 'drupal_get_form',
'page arguments' => array('inscription_newsletter_form'),
);
$items['form-newsletter-submissions'] = array(
'title' => 'Inscription Newsletter Submission',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('access inscription_newsletter submission'),
'page callback' => 'inscription_newsletter_submission',
);
return $items;
}
/**
* Inscription Newsletter Form
*/
function inscription_newsletter_form($form, &$form_state) {
$civil = array(t('Monsieur') => t('Monsieur'), t('Madame') => t('Madame'));
$form['civil']['civil'] = array(
'#type' => 'radios',
'#title' => t('Civilité'),
'#default_value' => '',
'#options' => $civil,
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Votre nom'),
'#required' => TRUE,
'#description' => t('Entrez votre nom.'),
);
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('Votre adresse email'),
'#size' => 60,
'#maxlength' => 128,
'#required' => TRUE,
'#description' => t('Entrez votre adresse email'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('S\'inscrire'),
);
return $form;
}
/**
* Implements hook_validate()
*/
function inscription_newsletter_validate($form, &$form_state) {
$valid_email = $form_state['values']['email'];
if (!valid_email_address($valid_email)) {
form_set_error('email', 'Votre adresse email -- ' . $valid_email . ' -- n\'est pas valide !');
}
}
/**
* Submit handler for the inscription_newsletter_form. Inserts entry into the database.
*/
function inscription_newsletter_form_submit($form, &$form_state) {
$fe_id = db_insert('inscription_newsletter')
->fields(array(
'civil' => $form_state['values']['civil'],
'name' => $form_state['values']['name'],
'email' => $form_state['values']['email'],
))
->execute();
drupal_set_message(t('Votre soumission a bien été prise en compte.'));
}
/**
* View the form submission
*/
function inscription_newsletter_submission() {
$results = db_query("SELECT * FROM {inscription_newsletter}");
$header = array(t('Id'), t('Civilité'), t('Nom'), t('Adresse email'));
$rows = array();
foreach ($results as $result) {
$rows[] = array(
check_plain($result->in_id),
check_plain($result->civil),
check_plain($result->name),
check_markup($result->email),
);
}
return theme('table', array('header' => $header, 'rows' => $rows));
} |
Partager