function invite_page_form in Invite 7.2
Same name and namespace in other branches
- 5.2 invite.module \invite_page_form()
- 6.2 invite.module \invite_page_form()
Generate the invite page form.
Parameters
$remaining_invite: Number of remaining invites.
$edit: Previous values when resending an invite.
Return value
A form definition.
1 call to invite_page_form()
- invite_form in ./
invite.module - Generate the invite forms.
File
- ./
invite.module, line 1012 - Allows your users to send and track invitations to join your site.
Code
function invite_page_form($remaining_invites, $edit = array()) {
global $user;
// Sender e-mail address.
if (!variable_get('invite_use_users_email', 0)) {
$from = variable_get('invite_manual_from', '');
}
elseif (!empty($user->mail)) {
$from = $user->mail;
}
if (empty($from)) {
$from = variable_get('site_mail', ini_get('sendmail_from'));
}
$form['from'] = array(
'#type' => 'item',
'#title' => t('From'),
'#markup' => check_plain($from),
);
// Recipient email address.
if (!$edit) {
$failed_emails = '';
$allow_multiple = user_access('send mass invitations');
if (isset($_SESSION['invite_failed_emails'])) {
$failed_emails = implode(', ', (array) unserialize($_SESSION['invite_failed_emails']));
unset($_SESSION['invite_failed_emails']);
}
$form['email'] = array(
'#title' => t('To'),
'#default_value' => $failed_emails,
'#description' => format_plural($allow_multiple ? 99 : 1, 'Enter the e-mail address of the person you would like to invite.', 'Enter the e-mail addresses of the persons you would like to invite. To specify multiple recipients, enter one e-mail address per line or separate each address with a comma.'),
'#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';
}
}
else {
// The email is not editable when resending an invite.
$allow_multiple = FALSE;
$form['email_markup'] = array(
'#type' => 'item',
'#title' => t('To'),
'#markup' => check_plain($edit['email']),
);
$form['email'] = array(
'#type' => 'value',
'#value' => $edit['email'],
);
}
// Message subject.
if ($edit && !empty($edit['data']['subject'])) {
$subject = $edit['data']['subject'];
}
else {
$subject = invite_get_subject();
}
// Add prefix.
$prefix = t('Re:');
if ($edit && drupal_substr($subject, 0, drupal_strlen($prefix)) != $prefix) {
$subject = $prefix . ' ' . $subject;
}
if (variable_get('invite_subject_editable', FALSE)) {
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#default_value' => $subject,
'#description' => t('Type the subject of the invitation e-mail.'),
'#required' => TRUE,
);
}
else {
$form['subject_markup'] = array(
'#type' => 'item',
'#title' => t('Subject'),
'#markup' => check_plain($subject),
);
$form['subject'] = array(
'#type' => 'value',
'#value' => $subject,
);
}
$default_message = variable_get('invite_mail_template_editable', TRUE) ? token_replace(_invite_get_mail_template(), invite_token_data()) : '';
$form['message'] = array(
'#title' => t('Message'),
'#type' => 'textarea',
'#default_value' => $edit && !empty($edit['data']['message']) ? $edit['data']['message'] : $default_message,
'#description' => t('This is the message the invitation email will contain. The <i>[invite:join-link]</i> token in the message will be replaced by the registration link the recipient can use to join. Make sure this token is always included in the message.'),
);
if (!variable_get('invite_mail_template_editable', TRUE)) {
$form['message']['#description'] = t('A personal message to be included in the invitation e-mail.');
}
// Remaining invites.
if ($remaining_invites != INVITE_UNLIMITED) {
$form['remaining_invites_markup'] = array(
'#type' => 'item',
'#markup' => format_plural($remaining_invites, 'You have 1 invite remaining.', 'You have @count invites remaining.'),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send invite in email'),
);
$form['submit_show'] = array(
'#type' => 'submit',
'#value' => t('Show registration link'),
);
if ($remaining_invites == 0 && !$edit) {
$form['submit']['#disabled'] = TRUE;
$form['submit_show']['#disabled'] = TRUE;
drupal_set_message('You have no more invitations left.', 'error');
}
return $form;
}