- 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
4.7.x
Dries Buytaert 2005-10-08 12:21:47 +00:00
parent 27625fcf83
commit 7863be5e82
13 changed files with 53 additions and 43 deletions

View File

@ -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.
*/

View File

@ -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));

View File

@ -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));

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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');
}

View File

@ -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');
}

View File

@ -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();

View File

@ -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();

View File

@ -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());

View File

@ -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());