function invite_form in Invite 5
Same name and namespace in other branches
- 5.2 invite.module \invite_form()
- 6.2 invite.module \invite_form()
- 7.4 includes/invite.admin.inc \invite_form()
- 7.2 invite.module \invite_form()
Generate the invite form.
Parameters
$op: The type of form to generate, 'page' or 'block'.
Return value
A form definition array.
2 string references to 'invite_form'
- invite_block in ./
invite.module - Implementation of hook_block().
- invite_menu in ./
invite.module - Implementation of hook_menu().
File
- ./
invite.module, line 605 - Allows your users to send and track invitations to join your site.
Code
function invite_form($op = 'page') {
global $user;
$max_invites = invite_max_invites();
$allow_multiple = user_access('send mass invitations');
// Check that the user is within limits
if ($max_invites != INVITE_UNLIMITED_INVITES) {
$invites_sent = db_result(db_query("SELECT COUNT(*) FROM {invite} WHERE uid = %d", $user->uid));
$invites_left = max($max_invites - $invites_sent, 0);
if ($invites_left == 0) {
if ($op == 'block') {
// Hide the block
$form['#access'] = FALSE;
return $form;
}
else {
drupal_set_message(t('Sorry, you reached the maximum number (@max) of invitations.', array(
'@max' => $max_invites,
)), 'error');
drupal_goto(user_access('track invitations') ? 'invite/list' : '<front>');
}
}
}
else {
$invites_left = INVITE_UNLIMITED_INVITES;
}
$form['remaining_invites'] = array(
'#type' => 'value',
'#value' => $invites_left,
);
switch ($op) {
case 'block':
$form['#action'] = url('invite');
$form['invite'] = array(
'#value' => t('Recommend @site-name to:', array(
'@site-name' => variable_get('site_name', t('Drupal')),
)),
);
$description = '';
if ($max_invites != INVITE_UNLIMITED_INVITES) {
$description = format_plural($invites_left, '1 invite left', '@count invites left');
}
$form['email'] = array(
'#type' => 'textfield',
'#size' => 20,
'#maxlength' => 64,
'#description' => $description,
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send invite'),
);
$form['link'] = array(
'#prefix' => '<div><small>',
'#value' => l(t('View your invites'), 'invite/list'),
'#suffix' => '</small></div>',
'#access' => user_access('track invitations'),
);
break;
case 'page':
default:
// Remaining invites
if ($max_invites != INVITE_UNLIMITED_INVITES) {
$form['remaining_invites_markup'] = array(
'#value' => format_plural($invites_left, 'You have 1 invite left.', 'You have @count invites left.'),
);
}
// Sender email address
if ($user->uid && variable_get('invite_use_users_email', 0)) {
$from = $user->mail;
}
else {
$from = variable_get('site_mail', ini_get('sendmail_from'));
}
// Personalize displayed email
// see http://drupal.org/project/pmail
if (module_exists('pmail')) {
$from = personalize_email($from);
}
$form['from'] = array(
'#type' => 'item',
'#title' => t('From'),
'#value' => check_plain($from),
);
// Recipient email address
$failed_emails = '';
if (isset($_SESSION['invite_failed_emails'])) {
$failed_emails = implode("\n", (array) unserialize($_SESSION['invite_failed_emails']));
unset($_SESSION['invite_failed_emails']);
}
$form['email'] = array(
'#title' => t('To'),
'#default_value' => $failed_emails,
'#description' => format_plural((int) $allow_multiple + 1, 'Type the e-mail address of the person you would like to invite.', 'Type the e-mail addresses of the persons you would like to invite. Addresses should be separated by newlines or commas.'),
'#required' => TRUE,
);
if ($allow_multiple) {
$form['email']['#type'] = 'textarea';
$form['email']['#rows'] = 3;
}
else {
$form['email']['#type'] = 'textfield';
$form['email']['#maxlength'] = 64;
}
if ($failed_emails) {
$form['email']['#attributes']['class'] = 'error';
}
// Message subject
$subject = invite_get_subject();
if (variable_get('invite_subject_editable', FALSE)) {
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#default_value' => $subject,
'#maxlength' => 64,
'#description' => t('Type the subject of the invitation e-mail.'),
'#required' => TRUE,
);
}
else {
$form['subject'] = array(
'#type' => 'item',
'#title' => t('Subject'),
'#value' => check_plain($subject),
);
}
// Message body
$form['body'] = array(
'#type' => 'item',
'#title' => t('Message'),
);
$form['message'] = array(
'#type' => 'textarea',
'#description' => format_plural((int) $allow_multiple + 1, 'This message will be added to the mail sent to the person you are inviting.', 'This message will be added to the mail sent to the persons you are inviting.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
break;
}
return $form;
}