| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: webform.pages.inc,v 1.10.2.3 2010/09/04 18:14:04 quicksketch Exp $ 3 4 /** 5 * @file 6 * 7 * Menu callbacks and functions for configuring and editing webforms. 8 */ 9 10 /** 11 * Main configuration form for editing a webform node. 12 */ 13 function webform_configure_form(&$form_state, $node) { 14 $form = array(); 15 16 // Add CSS and JS. Don't preprocess because these files are used rarely. 17 drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css', 'theme', 'all', FALSE); 18 drupal_add_js(drupal_get_path('module', 'webform') . '/js/webform-admin.js', 'module', 'header', FALSE, TRUE, FALSE); 19 20 $form['nid'] = array( 21 '#type' => 'value', 22 '#value' => $node->nid, 23 ); 24 25 /* Start Edit Form */ 26 $form['submission'] = array( 27 '#type' => 'fieldset', 28 '#title' => t('Submission settings'), 29 '#collapsible' => TRUE, 30 '#collapsed' => FALSE, 31 '#weight' => -4, 32 ); 33 34 $form['submission']['confirmation_wrapper']['confirmation'] = array( 35 '#type' => 'textarea', 36 '#title' => t('Confirmation message'), 37 '#description' => t('Message to be shown upon successful submission. If <em>Redirect URL</em> is set this displays as a message, otherwise it will be shown on its own page.'), 38 '#default_value' => $node->webform['confirmation'], 39 '#cols' => 40, 40 '#rows' => 10, 41 ); 42 43 $form['submission']['confirmation_wrapper']['format'] = filter_form($node->webform['confirmation_format'], NULL, array('confirmation_format')); 44 45 // Redirect URL. 46 $form['submission']['redirect_url'] = array( 47 '#type' => 'textfield', 48 '#title' => t('Redirect URL'), 49 '#description' => t('URL to redirect the user to upon successful submission.'), 50 '#default_value' => $node->webform['redirect_url'], 51 '#maxlength' => 255, 52 ); 53 54 // Submission limit settings. 55 $form['submission']['submit_limit'] = array( 56 '#type' => 'item', 57 '#title' => t('Submission limit'), 58 '#theme' => 'webform_advanced_submit_limit_form', 59 '#description' => t('Limit the number of submissions <em>per user</em>. A user is identified by their user login if logged-in, or by their IP Address and Cookie if anonymous. Use of cookies may be modified in the global <a href="!url">Webform settings</a>.', array('!url' => url('admin/settings/webform'))), 60 ); 61 $form['submission']['submit_limit']['enforce_limit'] = array( 62 '#type' => 'radios', 63 '#options' => array('no' => t('Unlimited'), 'yes' => 'Limit to !count submission(s) !timespan'), 64 '#default_value' => $node->webform['submit_limit'] == -1 ? 'no' : 'yes', 65 '#parents' => array('enforce_limit'), 66 ); 67 $form['submission']['submit_limit']['submit_limit'] = array( 68 '#type' => 'textfield', 69 '#maxlength' => 2, 70 '#size' => 2, 71 '#default_value' => $node->webform['submit_limit'] != -1 ? $node->webform['submit_limit'] : '', 72 '#parents' => array('submit_limit'), 73 ); 74 $form['submission']['submit_limit']['submit_interval'] = array( 75 '#type' => 'select', 76 '#options' => array( 77 '-1' => t('ever'), 78 '3600' => t('every hour'), 79 '86400' => t('every day'), 80 '604800' => t('every week'), 81 ), 82 '#default_value' => $node->webform['submit_interval'], 83 '#parents' => array('submit_interval'), 84 ); 85 86 /* End Edit Form */ 87 88 /* Start per-role submission control */ 89 $form['role_control'] = array( 90 '#type' => 'fieldset', 91 '#title' => t('Submission access'), 92 '#collapsible' => TRUE, 93 '#collapsed' => FALSE, 94 '#weight' => -3, 95 '#description' => t('These permissions affect which roles can submit this webform. It does not prevent access to the webform page. If needing to prevent access to the webform page entirely, use a content access module such as <a href="http://drupal.org/project/taxonomy_access">Taxonomy Access</a> or <a href="http://drupal.org/project/node_privacy_byrole">Node Privacy by Role</a>.'), 96 '#access' => variable_get('webform_submission_access_control', 1), 97 ); 98 $user_roles = user_roles(); 99 foreach ($user_roles as $rid => $rname) { 100 if ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID) { 101 continue; 102 } 103 $user_roles[$rid] = webform_tt("user:rid:$rid:name", $rname); 104 } 105 $form['role_control']['roles'] = array( 106 '#default_value' => $node->webform['roles'], 107 '#options' => $user_roles, 108 '#type' => 'checkboxes', 109 '#title' => t('Roles that can submit this webform'), 110 '#description' => t('Uncheck all roles to prevent new submissions. The %authenticated role applies to any user signed into the site, regardless of other assigned roles.', array('%authenticated' => $user_roles[2])), 111 ); 112 /* End per-role submission control */ 113 114 /* Start advanced settings form */ 115 $form['advanced'] = array( 116 '#type' => 'fieldset', 117 '#title' => t('Advanced settings'), 118 '#collapsible' => TRUE, 119 '#collapsed' => TRUE, 120 '#weight' => -1, 121 ); 122 $form['advanced']['teaser'] = array( 123 '#type' => 'checkbox', 124 '#title' => t('Show complete form in teaser'), 125 '#default_value' => $node->webform['teaser'], 126 '#description' => t('Display the entire form in the teaser display of this node.'), 127 ); 128 $form['advanced']['allow_draft'] = array( 129 '#type' => 'checkbox', 130 '#title' => t('Allow users to save a draft'), 131 '#default_value' => $node->webform['allow_draft'], 132 '#description' => t('Allow your users to save and finish the form later.'), 133 ); 134 $form['advanced']['submit_notice'] = array( 135 '#type' => 'checkbox', 136 '#title' => t('Show the notification about previous submissions.'), 137 '#default_value' => $node->webform['submit_notice'], 138 '#description' => t('Show the previous submissions notification that appears when users have previously submitted this form.'), 139 ); 140 $form['advanced']['submit_text'] = array( 141 '#type' => 'textfield', 142 '#title' => t('Submit button text'), 143 '#default_value' => $node->webform['submit_text'], 144 '#description' => t('By default the submit button on this form will have the label <em>Submit</em>. Enter a new title here to override the default.'), 145 ); 146 /* End Advanced Settings Form */ 147 148 $form['submit'] = array( 149 '#type' => 'submit', 150 '#value' => t('Save configuration'), 151 '#weight' => 300, 152 ); 153 154 return $form; 155 } 156 157 /** 158 * Validate handler for webform_configure_form(). 159 */ 160 function webform_configure_form_validate($form, &$form_state) { 161 // Ensure the entered e-mail addresses are valid. 162 if (!empty($form_state['values']['email'])) { 163 $emails = explode(',', $form_state['values']['email']); 164 foreach ($emails as $email) { 165 if (!valid_email_address(trim($email))) { 166 form_error($form['submission']['redirect_url'], t('The entered email address %address is not a valid address.', array('%address' => $email))); 167 break; 168 } 169 } 170 } 171 172 // Ensure the entered redirect URL is valid. 173 $redirect_url = trim($form_state['values']['redirect_url']); 174 if (!empty($redirect_url) && strpos($redirect_url, 'http') === 0 && !valid_url($redirect_url, TRUE)) { 175 form_error($form['submission']['redirect_url'], t('The entered URL is not a valid address.')); 176 } 177 else { 178 form_set_value($form['submission']['redirect_url'], $redirect_url, $form_state); 179 } 180 } 181 182 /** 183 * Submit handler for webform_configure_form(). 184 */ 185 function webform_configure_form_submit($form, &$form_state) { 186 $node = node_load($form_state['values']['nid']); 187 188 // Save the confirmation. 189 $node->webform['confirmation'] = $form_state['values']['confirmation']; 190 $node->webform['confirmation_format'] = $form_state['values']['confirmation_format']; 191 192 // Save the redirect URL 193 $node->webform['redirect_url'] = $form_state['values']['redirect_url']; 194 195 // Save roles. 196 $node->webform['roles'] = array_keys(array_filter($form_state['values']['roles'])); 197 198 // Set the Show complete form in teaser setting. 199 $node->webform['teaser'] = $form_state['values']['teaser']; 200 201 // Set the draft option. 202 $node->webform['allow_draft'] = $form_state['values']['allow_draft']; 203 204 // Set the submit limit to -1 if set to unlimited. 205 if ($form_state['values']['enforce_limit'] == 'no') { 206 $node->webform['submit_limit'] = -1; 207 $node->webform['submit_interval'] = -1; 208 } 209 else { 210 $node->webform['submit_limit'] = $form_state['values']['submit_limit']; 211 $node->webform['submit_interval'] = $form_state['values']['submit_interval']; 212 } 213 214 // Set submit notice. 215 $node->webform['submit_notice'] = $form_state['values']['submit_notice']; 216 217 // Set submit button text. 218 $node->webform['submit_text'] = $form_state['values']['submit_text']; 219 220 node_save($node); 221 222 drupal_set_message(t('The form settings have been updated.')); 223 } 224 225 /** 226 * Theme the submit limit fieldset on the webform node form. 227 */ 228 function theme_webform_advanced_submit_limit_form($form) { 229 $form['submit_limit']['#attributes']['class'] = 'webform-set-active'; 230 $form['submit_interval']['#attributes']['class'] = 'webform-set-active'; 231 // Remove div wrappers around limit options. 232 $replacements = array( 233 '!count' => preg_replace('/(<div[^>]*>)(.*?)(<\/div>)/s', '$2', drupal_render($form['submit_limit'])), 234 '!timespan' => preg_replace('/(<div[^>]*>)(.*?)(<\/div>)/s', '$2', drupal_render($form['submit_interval'])), 235 ); 236 $form['enforce_limit']['yes']['#title'] = t('Limit to !count submission(s) !timespan', $replacements); 237 return drupal_render($form); 238 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |