diff options
author | Dries Buytaert <dries@buytaert.net> | 2005-10-08 12:21:47 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2005-10-08 12:21:47 +0000 |
commit | 7863be5e82ccfbaa4aa9bac2343ad9e560130b44 (patch) | |
tree | 4af8979d342a4ce8244fc005162f6d313692ab3d | |
parent | 27625fcf836b321f2999569d7d9508735388094e (diff) | |
download | brdo-7863be5e82ccfbaa4aa9bac2343ad9e560130b44.tar.gz brdo-7863be5e82ccfbaa4aa9bac2343ad9e560130b44.tar.bz2 |
- Patch #33433 by chx: fixed a number of form API problems.
* Default form value
* Leftover debug function in form.inc
* PHP5 issue with comment date (I got this patch from another issue)
* Validation error fix (was calling legacy form validate)
* Lots o' warnings on comment preview
* Filter tips plus argument (gremlins. I swear this was not there.)
* Message to clear what's going on with system settings
* Non-freetagging taxonomies fixed
-rw-r--r-- | includes/form.inc | 8 | ||||
-rw-r--r-- | modules/comment.module | 9 | ||||
-rw-r--r-- | modules/comment/comment.module | 9 | ||||
-rw-r--r-- | modules/filter.module | 2 | ||||
-rw-r--r-- | modules/filter/filter.module | 2 | ||||
-rw-r--r-- | modules/node.module | 16 | ||||
-rw-r--r-- | modules/node/node.module | 16 | ||||
-rw-r--r-- | modules/system.module | 4 | ||||
-rw-r--r-- | modules/system/system.module | 4 | ||||
-rw-r--r-- | modules/taxonomy.module | 10 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.module | 10 | ||||
-rw-r--r-- | modules/watchdog.module | 3 | ||||
-rw-r--r-- | modules/watchdog/watchdog.module | 3 |
13 files changed, 53 insertions, 43 deletions
diff --git a/includes/form.inc b/includes/form.inc index 0408db883..42240001c 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -517,7 +517,7 @@ function _form_builder($form, $parents = array(), $multiple = FALSE) { $ref =& $ref[$parent]; } $default_value = $posted ? $edit : $form[default_value]; - $form[value] = $form[value] ? $form[value] : $default_value; + $form[value] = isset($form[value]) ? $form[value] : $default_value; if (isset($form[execute])) { if ($_POST[$form[name]] == $form[value]) { $form_execute = $form_execute || $form[execute]; @@ -593,12 +593,6 @@ function form_render(&$elements) { return $elements[prefix] . $content . $elements[suffix]; } -function _print_rp($var) { - echo "<pre>"; - print_r($var); - echo "</pre>"; -} - /** * Function used by uasort in form render to sort form via weight. */ diff --git a/modules/comment.module b/modules/comment.module index d932b6214..3be3ef28d 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -417,8 +417,9 @@ function comment_validate(&$edit) { $edit['status'] = user_access('post comments without approval') ? 0 : 1; } else { - if (strtotime($edit['date']) != -1) { - $edit['timestamp'] = strtotime($edit['date']); + $date = isset($edit['date']) ? $edit['date'] : 'now'; + if (strtotime($date) != -1) { + $edit['timestamp'] = strtotime($date); } else { form_set_error('date', t('You have to specify a valid date.')); @@ -492,8 +493,6 @@ function comment_validate(&$edit) { } } } - // verify that this submission was actually generated using a local form - form_validate($edit, 'comment'. $edit['nid'] . $edit['pid']); return $edit; } @@ -522,7 +521,7 @@ function comment_preview($edit) { if (!form_get_errors()) { $output .= theme('comment_view', $comment); } - $output .= theme('comment_form', $edit, t('Reply')); + $output .= comment_form($edit, t('Reply')); if ($edit['pid']) { $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $edit['pid'], COMMENT_PUBLISHED)); diff --git a/modules/comment/comment.module b/modules/comment/comment.module index d932b6214..3be3ef28d 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -417,8 +417,9 @@ function comment_validate(&$edit) { $edit['status'] = user_access('post comments without approval') ? 0 : 1; } else { - if (strtotime($edit['date']) != -1) { - $edit['timestamp'] = strtotime($edit['date']); + $date = isset($edit['date']) ? $edit['date'] : 'now'; + if (strtotime($date) != -1) { + $edit['timestamp'] = strtotime($date); } else { form_set_error('date', t('You have to specify a valid date.')); @@ -492,8 +493,6 @@ function comment_validate(&$edit) { } } } - // verify that this submission was actually generated using a local form - form_validate($edit, 'comment'. $edit['nid'] . $edit['pid']); return $edit; } @@ -522,7 +521,7 @@ function comment_preview($edit) { if (!form_get_errors()) { $output .= theme('comment_view', $comment); } - $output .= theme('comment_form', $edit, t('Reply')); + $output .= comment_form($edit, t('Reply')); if ($edit['pid']) { $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $edit['pid'], COMMENT_PUBLISHED)); diff --git a/modules/filter.module b/modules/filter.module index 27bba7941..8d396bc59 100644 --- a/modules/filter.module +++ b/modules/filter.module @@ -764,7 +764,7 @@ function filter_form($value = FILTER_FORMAT_DEFAULT) { $format = array_shift($formats); $form['format'][$format->name] = array(type => 'value', value => $format->format); $tips = _filter_tips(variable_get('filter_default_format', 1), false); - $form['format']['guidelines'] = array(type => 'item', title => t('Formatting guidelines'), value => theme('filter_tips', $tips, false, $extra), $extra); + $form['format']['guidelines'] = array(type => 'markup', title => t('Formatting guidelines'), value => theme('filter_tips', $tips, false, $extra)); return $form; } } diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 27bba7941..8d396bc59 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -764,7 +764,7 @@ function filter_form($value = FILTER_FORMAT_DEFAULT) { $format = array_shift($formats); $form['format'][$format->name] = array(type => 'value', value => $format->format); $tips = _filter_tips(variable_get('filter_default_format', 1), false); - $form['format']['guidelines'] = array(type => 'item', title => t('Formatting guidelines'), value => theme('filter_tips', $tips, false, $extra), $extra); + $form['format']['guidelines'] = array(type => 'markup', title => t('Formatting guidelines'), value => theme('filter_tips', $tips, false, $extra)); return $form; } } diff --git a/modules/node.module b/modules/node.module index 59fe91a8c..c684e4362 100644 --- a/modules/node.module +++ b/modules/node.module @@ -1291,8 +1291,7 @@ function node_feed($nodes = 0, $channel = array()) { // Allow modules to add additional item fields $extra = node_invoke_nodeapi($item, 'rss item'); - $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), - array('key' => 'dc:creator', 'value' => $item->name))); + $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name))); foreach ($extra as $element) { if ($element['namespace']) { $namespaces = array_merge($namespaces, array($element['namespace'])); @@ -1432,13 +1431,14 @@ function node_form($node) { /** * Basic node information. - * These elements set the value property, making them immutable. + * These elements are just values so they are not even sent to the client. */ - $form['nid'] = array(type => 'hidden', value => $node->nid); - $form['uid'] = array(type => 'hidden', value => $node->uid); - $form['created'] = array(type => 'hidden', value => $node->created); - $form['changed'] = array(type => 'hidden', value => $node->changed); - $form['type'] = array(type => 'hidden', value => $node->type); + $form['nid'] = array(type => 'value', value => $node->nid); + $form['vid'] = array(type => 'value', value => $node->vid); + $form['uid'] = array(type => 'value', value => $node->uid); + $form['created'] = array(type => 'value', value => $node->created); + $form['changed'] = array(type => 'value', value => $node->changed); + $form['type'] = array(type => 'value', value => $node->type); if ($op == t('Preview')) { $form['node_preview'] = array(value => node_preview(array2object($_POST['edit'])), weight => -100); diff --git a/modules/node/node.module b/modules/node/node.module index 59fe91a8c..c684e4362 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1291,8 +1291,7 @@ function node_feed($nodes = 0, $channel = array()) { // Allow modules to add additional item fields $extra = node_invoke_nodeapi($item, 'rss item'); - $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), - array('key' => 'dc:creator', 'value' => $item->name))); + $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name))); foreach ($extra as $element) { if ($element['namespace']) { $namespaces = array_merge($namespaces, array($element['namespace'])); @@ -1432,13 +1431,14 @@ function node_form($node) { /** * Basic node information. - * These elements set the value property, making them immutable. + * These elements are just values so they are not even sent to the client. */ - $form['nid'] = array(type => 'hidden', value => $node->nid); - $form['uid'] = array(type => 'hidden', value => $node->uid); - $form['created'] = array(type => 'hidden', value => $node->created); - $form['changed'] = array(type => 'hidden', value => $node->changed); - $form['type'] = array(type => 'hidden', value => $node->type); + $form['nid'] = array(type => 'value', value => $node->nid); + $form['vid'] = array(type => 'value', value => $node->vid); + $form['uid'] = array(type => 'value', value => $node->uid); + $form['created'] = array(type => 'value', value => $node->created); + $form['changed'] = array(type => 'value', value => $node->changed); + $form['type'] = array(type => 'value', value => $node->type); if ($op == t('Preview')) { $form['node_preview'] = array(value => node_preview(array2object($_POST['edit'])), weight => -100); diff --git a/modules/system.module b/modules/system.module index 8b5a2338b..387c3b195 100644 --- a/modules/system.module +++ b/modules/system.module @@ -637,6 +637,10 @@ function system_settings_form($form_id, $form) { $form['buttons']['submit'] = array(type => 'submit', value => t('Save configuration') ); $form['buttons']['reset'] = array(type => 'submit', value => t('Reset to defaults') ); + if (!empty($_POST) && form_get_errors()) { + drupal_set_message(t('Your settings are not saved because of the errors above'), 'error'); + } + return drupal_get_form($form_id, $form, 'system_settings_form'); } diff --git a/modules/system/system.module b/modules/system/system.module index 8b5a2338b..387c3b195 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -637,6 +637,10 @@ function system_settings_form($form_id, $form) { $form['buttons']['submit'] = array(type => 'submit', value => t('Save configuration') ); $form['buttons']['reset'] = array(type => 'submit', value => t('Reset to defaults') ); + if (!empty($_POST) && form_get_errors()) { + drupal_set_message(t('Your settings are not saved because of the errors above'), 'error'); + } + return drupal_get_form($form_id, $form, 'system_settings_form'); } diff --git a/modules/taxonomy.module b/modules/taxonomy.module index 82b23ce92..eb4ddf67f 100644 --- a/modules/taxonomy.module +++ b/modules/taxonomy.module @@ -520,13 +520,17 @@ function taxonomy_node_form($type, $node = '', $help = NULL, $name = 'taxonomy') $typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL); - $form[$name]['tags'][$vocabulary->vid] = array( type => textfield, default_value => $typed_string, size => 60, maxlength => 100, - autocomplete_path => 'taxonomy/autocomplete/'. $vocabulary->vid, required => ($vocabulary->required ? TRUE : FALSE), title => $vocabulary->name, - description => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").') ); + $form[$name]['tags'][$vocabulary->vid] = array(type => textfield, default_value => $typed_string, size => 60, maxlength => 100, autocomplete_path => 'taxonomy/autocomplete/'. $vocabulary->vid, required => $vocabulary->required, title => $vocabulary->name, description => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").')); } else { $ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms); $form[$name][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name); + if ($vocabulary->multiple) { + $form[$name][$vocabulary->vid][parents] = array($name); + } + else { + $form[$name][$vocabulary->vid][tree] = TRUE; + } } } return $form ? $form : array(); diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 82b23ce92..eb4ddf67f 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -520,13 +520,17 @@ function taxonomy_node_form($type, $node = '', $help = NULL, $name = 'taxonomy') $typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL); - $form[$name]['tags'][$vocabulary->vid] = array( type => textfield, default_value => $typed_string, size => 60, maxlength => 100, - autocomplete_path => 'taxonomy/autocomplete/'. $vocabulary->vid, required => ($vocabulary->required ? TRUE : FALSE), title => $vocabulary->name, - description => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").') ); + $form[$name]['tags'][$vocabulary->vid] = array(type => textfield, default_value => $typed_string, size => 60, maxlength => 100, autocomplete_path => 'taxonomy/autocomplete/'. $vocabulary->vid, required => $vocabulary->required, title => $vocabulary->name, description => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").')); } else { $ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms); $form[$name][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name); + if ($vocabulary->multiple) { + $form[$name][$vocabulary->vid][parents] = array($name); + } + else { + $form[$name][$vocabulary->vid][tree] = TRUE; + } } } return $form ? $form : array(); diff --git a/modules/watchdog.module b/modules/watchdog.module index 6e2066cdd..22c1ad0f3 100644 --- a/modules/watchdog.module +++ b/modules/watchdog.module @@ -89,6 +89,7 @@ function watchdog_overview() { ); $form['submit'] = array(type => 'submit', value =>t('Filter')); + $output = drupal_get_form('watchdog_form_overview', $form); $header = array( ' ', @@ -122,7 +123,7 @@ function watchdog_overview() { $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7')); } - $output = drupal_get_form('watchdog_form_overview', $form); + $output .= theme('table', $header, $rows); $output .= theme('pager', NULL, 50, 0, tablesort_pager()); diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module index 6e2066cdd..22c1ad0f3 100644 --- a/modules/watchdog/watchdog.module +++ b/modules/watchdog/watchdog.module @@ -89,6 +89,7 @@ function watchdog_overview() { ); $form['submit'] = array(type => 'submit', value =>t('Filter')); + $output = drupal_get_form('watchdog_form_overview', $form); $header = array( ' ', @@ -122,7 +123,7 @@ function watchdog_overview() { $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7')); } - $output = drupal_get_form('watchdog_form_overview', $form); + $output .= theme('table', $header, $rows); $output .= theme('pager', NULL, 50, 0, tablesort_pager()); |