From 7863be5e82ccfbaa4aa9bac2343ad9e560130b44 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 8 Oct 2005 12:21:47 +0000 Subject: [PATCH] - 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 --- includes/form.inc | 8 +------- modules/comment.module | 9 ++++----- modules/comment/comment.module | 9 ++++----- modules/filter.module | 2 +- modules/filter/filter.module | 2 +- modules/node.module | 16 ++++++++-------- modules/node/node.module | 16 ++++++++-------- modules/system.module | 4 ++++ modules/system/system.module | 4 ++++ modules/taxonomy.module | 10 +++++++--- modules/taxonomy/taxonomy.module | 10 +++++++--- modules/watchdog.module | 3 ++- modules/watchdog/watchdog.module | 3 ++- 13 files changed, 53 insertions(+), 43 deletions(-) diff --git a/includes/form.inc b/includes/form.inc index 0408db88327..42240001cef 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 "
";
-  print_r($var);
-  echo "
"; -} - /** * Function used by uasort in form render to sort form via weight. */ diff --git a/modules/comment.module b/modules/comment.module index d932b621490..3be3ef28d26 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 d932b621490..3be3ef28d26 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 27bba79410e..8d396bc5973 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 27bba79410e..8d396bc5973 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 59fe91a8c56..c684e4362d5 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 59fe91a8c56..c684e4362d5 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 8b5a2338bef..387c3b19516 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 8b5a2338bef..387c3b19516 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 82b23ce928e..eb4ddf67fbf 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 82b23ce928e..eb4ddf67fbf 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 6e2066cdd86..22c1ad0f382 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 6e2066cdd86..22c1ad0f382 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());