Commit fe2b3e7c authored by Dries's avatar Dries

- Patch by Steven and me: refactored the form handling of nodes. The node system is now using form_set_error() and friends like the rest of Drupal does. This makes for both a consistent user experience and consistent code. It simplifies the forms and validation code, however, it does change the node API slightly:

    * The _validate hook and the _nodeapi('validate') hook of the node API (1) no longer take an 'error' parameter and (2) should no longer return an error array. To set an error, call form_set_error().

    * The _form hook of the node module no longer takes a form hook and should not worry about displaying errors. Ditto for _nodeapi('form_post') and _nodeapi('form_pre').
parent 353c05d0
......@@ -961,9 +961,9 @@ function form_set_error($name, $message) {
}
/**
* Return true when errors have been set.
* Return an associative array of all errors.
*/
function form_has_errors() {
function form_get_errors() {
if (array_key_exists('form', $GLOBALS)) {
return $GLOBALS['form'];
}
......
......@@ -181,16 +181,14 @@ function blog_page_last() {
*/
function blog_validate(&$node) {
if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_blog_size', 0)) {
$error['body'] = theme('error', t('The body of your blog is too short.'));
form_set_error('body', t('The body of your blog is too short.'));
}
return $error;
}
/**
* Implementation of hook_form().
*/
function blog_form(&$node, &$error) {
function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
......@@ -214,7 +212,7 @@ function blog_form(&$node, &$error) {
$output .= implode('', taxonomy_node_form('blog', $node));
}
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 15, $error['body'] ? $error['body'] : filter_tips_short());
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 15, filter_tips_short());
return $output;
}
......
......@@ -181,16 +181,14 @@ function blog_page_last() {
*/
function blog_validate(&$node) {
if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_blog_size', 0)) {
$error['body'] = theme('error', t('The body of your blog is too short.'));
form_set_error('body', t('The body of your blog is too short.'));
}
return $error;
}
/**
* Implementation of hook_form().
*/
function blog_form(&$node, &$error) {
function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
......@@ -214,7 +212,7 @@ function blog_form(&$node, &$error) {
$output .= implode('', taxonomy_node_form('blog', $node));
}
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 15, $error['body'] ? $error['body'] : filter_tips_short());
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 15, filter_tips_short());
return $output;
}
......
......@@ -131,10 +131,10 @@ function blogapi_new_post($req_params) {
'comment' => $comment,
'moderate' => $moderate,
'revision' => $revision
), $error);
));
if (count($error) > 0) {
return blogapi_error($error);
if (form_get_errors()) {
return blogapi_error();
}
if (!node_access('create', $node)) {
......@@ -191,10 +191,10 @@ function blogapi_edit_post($req_params) {
$node->title = $title;
$node->body = $body;
$node->status = $params[4];
$node = node_validate($node, $error);
$node = node_validate($node);
if (count($error) > 0) {
return blogapi_error($error);
if (form_get_errors()) {
return blogapi_error();
}
$terms = module_invoke('taxonomy', 'node_get_terms', $node->nid, 'tid');
......@@ -402,10 +402,16 @@ function blogapi_convert($params) {
function blogapi_error($message) {
global $xmlrpcusererr;
if (is_array($message)) {
$message = implode('', $message);
if (!is_array($message)) {
$message = array($message);
}
if ($errors = form_get_errors()) {
$message = $message + $errors;
}
$message = implode(' ', $message);
return new xmlrpcresp(0, $xmlrpcusererr + 1, strip_tags($message));
}
......
......@@ -131,10 +131,10 @@ function blogapi_new_post($req_params) {
'comment' => $comment,
'moderate' => $moderate,
'revision' => $revision
), $error);
));
if (count($error) > 0) {
return blogapi_error($error);
if (form_get_errors()) {
return blogapi_error();
}
if (!node_access('create', $node)) {
......@@ -191,10 +191,10 @@ function blogapi_edit_post($req_params) {
$node->title = $title;
$node->body = $body;
$node->status = $params[4];
$node = node_validate($node, $error);
$node = node_validate($node);
if (count($error) > 0) {
return blogapi_error($error);
if (form_get_errors()) {
return blogapi_error();
}
$terms = module_invoke('taxonomy', 'node_get_terms', $node->nid, 'tid');
......@@ -402,10 +402,16 @@ function blogapi_convert($params) {
function blogapi_error($message) {
global $xmlrpcusererr;
if (is_array($message)) {
$message = implode('', $message);
if (!is_array($message)) {
$message = array($message);
}
if ($errors = form_get_errors()) {
$message = $message + $errors;
}
$message = implode(' ', $message);
return new xmlrpcresp(0, $xmlrpcusererr + 1, strip_tags($message));
}
......
......@@ -228,7 +228,7 @@ function book_validate(&$node) {
/**
* Implementation of hook_form().
*/
function book_form(&$node, &$error) {
function book_form(&$node) {
global $user;
$op = $_POST['op'];
......
......@@ -228,7 +228,7 @@ function book_validate(&$node) {
/**
* Implementation of hook_form().
*/
function book_form(&$node, &$error) {
function book_form(&$node) {
global $user;
$op = $_POST['op'];
......
......@@ -316,7 +316,7 @@ function comment_post($edit) {
$edit['subject'] = truncate_utf8(strip_tags($edit['comment']), 29);
}
if (!form_has_errors()) {
if (!form_get_errors()) {
// Check for duplicate comments. Note that we have to use the
// validated/filtered data to perform such check.
......@@ -1255,7 +1255,7 @@ function theme_comment_form($edit, $title) {
$form .= form_submit(t('Preview comment'));
}
if (!form_has_errors()) {
if (!form_get_errors()) {
$form .= form_submit(t('Post comment'));
}
......
......@@ -316,7 +316,7 @@ function comment_post($edit) {
$edit['subject'] = truncate_utf8(strip_tags($edit['comment']), 29);
}
if (!form_has_errors()) {
if (!form_get_errors()) {
// Check for duplicate comments. Note that we have to use the
// validated/filtered data to perform such check.
......@@ -1255,7 +1255,7 @@ function theme_comment_form($edit, $title) {
$form .= form_submit(t('Preview comment'));
}
if (!form_has_errors()) {
if (!form_get_errors()) {
$form .= form_submit(t('Post comment'));
}
......
......@@ -29,16 +29,16 @@ function drupal_help($section) {
function drupal_settings() {
// Check if all required fields are present for the Drupal directory
if ((variable_get('site_name', 'drupal') == 'drupal') || (variable_get('site_name', 'drupal') == ''))
$error['drupal_directory'] = theme('error', t("You must set your site's name on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
form_set_error('drupal_directory', t("You must set your site's name on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
else if (variable_get('site_mail', ini_get('sendmail_from')) == '')
$error['drupal_directory'] = theme('error', t("You must set your site's e-mail address on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
form_set_error('drupal_directory', t("You must set your site's e-mail address on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
else if (variable_get('site_slogan', '') == '')
$error['drupal_directory'] = theme('error', t("You must set your site's slogan on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
form_set_error('drupal_directory', t("You must set your site's slogan on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
else if (variable_get('site_mission', '') == '')
$error['drupal_directory'] = theme('error', t("You must set your site's mission on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
form_set_error('drupal_directory', t("You must set your site's mission on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
$output = form_textfield(t('Drupal XML-RPC server'), 'drupal_server', variable_get('drupal_server', 'http://www.drupal.org/xmlrpc.php'), 55, 128, t('The URL of your root Drupal XML-RPC server.'));
$output .= form_radios(t('Drupal directory'), 'drupal_directory', variable_get('drupal_directory', 0), array(t('Disabled'), t('Enabled')), t("If enabled, your Drupal site will make itself known to the Drupal directory at the specified Drupal XML-RPC server. For this to work properly, you must set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"%drupal-xml-rpc\", your web site will get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%drupal-sites" => "http://www.drupal.org/sites/")) . $error['drupal_directory']);
$output .= form_radios(t('Drupal directory'), 'drupal_directory', variable_get('drupal_directory', 0), array(t('Disabled'), t('Enabled')), t("If enabled, your Drupal site will make itself known to the Drupal directory at the specified Drupal XML-RPC server. For this to work properly, you must set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"%drupal-xml-rpc\", your web site will get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%drupal-sites" => "http://www.drupal.org/sites/")));
return $output;
}
......
......@@ -29,16 +29,16 @@ function drupal_help($section) {
function drupal_settings() {
// Check if all required fields are present for the Drupal directory
if ((variable_get('site_name', 'drupal') == 'drupal') || (variable_get('site_name', 'drupal') == ''))
$error['drupal_directory'] = theme('error', t("You must set your site's name on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
form_set_error('drupal_directory', t("You must set your site's name on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
else if (variable_get('site_mail', ini_get('sendmail_from')) == '')
$error['drupal_directory'] = theme('error', t("You must set your site's e-mail address on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
form_set_error('drupal_directory', t("You must set your site's e-mail address on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
else if (variable_get('site_slogan', '') == '')
$error['drupal_directory'] = theme('error', t("You must set your site's slogan on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
form_set_error('drupal_directory', t("You must set your site's slogan on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
else if (variable_get('site_mission', '') == '')
$error['drupal_directory'] = theme('error', t("You must set your site's mission on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
form_set_error('drupal_directory', t("You must set your site's mission on the <a href=\"%url\">administer &raquo; settings</a> page.", array('%url' => url('admin/settings'))));
$output = form_textfield(t('Drupal XML-RPC server'), 'drupal_server', variable_get('drupal_server', 'http://www.drupal.org/xmlrpc.php'), 55, 128, t('The URL of your root Drupal XML-RPC server.'));
$output .= form_radios(t('Drupal directory'), 'drupal_directory', variable_get('drupal_directory', 0), array(t('Disabled'), t('Enabled')), t("If enabled, your Drupal site will make itself known to the Drupal directory at the specified Drupal XML-RPC server. For this to work properly, you must set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"%drupal-xml-rpc\", your web site will get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%drupal-sites" => "http://www.drupal.org/sites/")) . $error['drupal_directory']);
$output .= form_radios(t('Drupal directory'), 'drupal_directory', variable_get('drupal_directory', 0), array(t('Disabled'), t('Enabled')), t("If enabled, your Drupal site will make itself known to the Drupal directory at the specified Drupal XML-RPC server. For this to work properly, you must set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"%drupal-xml-rpc\", your web site will get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%drupal-sites" => "http://www.drupal.org/sites/")));
return $output;
}
......
......@@ -246,7 +246,7 @@ function forum_validate(&$node) {
if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) {
if (in_array($term, $containers)) {
$term = taxonomy_get_term($term);
$error['taxonomy'] = theme('error', t('The item \'%forum\' is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
form_set_error('taxonomy', t('The item \'%forum\' is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
}
else {
$node->tid = $term;
......@@ -254,19 +254,18 @@ function forum_validate(&$node) {
}
}
}
return $error;
}
/**
* Implementation of hook_form().
*/
function forum_form(&$node, &$error) {
function forum_form(&$node) {
if (!$node->nid) {
// new topic
$node->taxonomy[] = arg(3);
}
$output = implode('', taxonomy_node_form('forum', $node, $error));
$output = implode('', taxonomy_node_form('forum', $node));
if ($node->nid) {
// if editing, give option to leave shadows
......
......@@ -246,7 +246,7 @@ function forum_validate(&$node) {
if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) {
if (in_array($term, $containers)) {
$term = taxonomy_get_term($term);
$error['taxonomy'] = theme('error', t('The item \'%forum\' is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
form_set_error('taxonomy', t('The item \'%forum\' is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
}
else {
$node->tid = $term;
......@@ -254,19 +254,18 @@ function forum_validate(&$node) {
}
}
}
return $error;
}
/**
* Implementation of hook_form().
*/
function forum_form(&$node, &$error) {
function forum_form(&$node) {
if (!$node->nid) {
// new topic
$node->taxonomy[] = arg(3);
}
$output = implode('', taxonomy_node_form('forum', $node, $error));
$output = implode('', taxonomy_node_form('forum', $node));
if ($node->nid) {
// if editing, give option to leave shadows
......
......@@ -1035,9 +1035,8 @@ function node_feed($nodes = 0, $channel = array()) {
/**
* Preform validation checks on the given node.
*/
function node_validate($node, &$error) {
function node_validate($node) {
global $user;
$error = array();
// Convert the node to an object, if necessary.
$node = array2object($node);
......@@ -1046,7 +1045,7 @@ function node_validate($node, &$error) {
if (isset($node->title)) {
$node->title = strip_tags($node->title);
if (!$node->title) {
$error['title'] = theme('error', t('You have to specify a valid title.'));
form_set_error('title', t('You have to specify a valid title.'));
}
}
......@@ -1081,7 +1080,7 @@ function node_validate($node, &$error) {
$node->uid = $account->uid;
}
else {
$error['name'] = theme('error', t("The name '%u' does not exist.", array ('%u' => $node->name)));
form_set_error('name', t("The name '%u' does not exist.", array ('%u' => $node->name)));
}
// Validate the "authored on" field.
......@@ -1089,7 +1088,7 @@ function node_validate($node, &$error) {
$node->created = strtotime($node->date);
}
else {
$error['date'] = theme('error', t('You have to specifiy a valid date.'));
form_set_error('date', t('You have to specifiy a valid date.'));
}
}
else {
......@@ -1105,8 +1104,10 @@ function node_validate($node, &$error) {
}
// Do node-type-specific validation checks.
$result = node_invoke($node, 'validate');
$error = $error + (is_array($result) ? $result : array()) + node_invoke_nodeapi($node, 'validate');
node_invoke($node, 'validate');
node_invoke_nodeapi($node, 'validate');
$node->validated = true;
return $node;
}
......@@ -1114,24 +1115,24 @@ function node_validate($node, &$error) {
/**
* Generate the node editing form.
*/
function node_form($edit, $error = NULL) {
function node_form($edit) {
// Validate the node if we don't already know the errors.
if ($error === NULL) {
$edit = node_validate($edit, $error);
if (!$edit->validated) {
$edit = node_validate($edit);
}
// Prepend extra node form elements.
$form = implode('', node_invoke_nodeapi($edit, 'form pre', $error));
$form = implode('', node_invoke_nodeapi($edit, 'form pre'));
// Get the node-specific bits.
// We can't use node_invoke() because $error and $param must be passed by reference.
// We can't use node_invoke() because $param must be passed by reference.
$function = node_get_module_name($edit) .'_form';
if (function_exists($function)) {
$form .= $function($edit, $error, $param);
$form .= $function($edit, $param);
}
// Append extra node form elements.
$form .= implode('', node_invoke_nodeapi($edit, 'form post', $error));
$form .= implode('', node_invoke_nodeapi($edit, 'form post'));
$output .= '<div class="node-form">';
......@@ -1140,8 +1141,8 @@ function node_form($edit, $error = NULL) {
if (user_access('administer nodes')) {
$output .= '<div class="admin">';
$author = form_textfield(t('Authored by'), 'name', $edit->name, 20, 60, $error['name']);
$author .= form_textfield(t('Authored on'), 'date', $edit->date, 20, 25, $error['date']);
$author = form_textfield(t('Authored by'), 'name', $edit->name, 20, 60);
$author .= form_textfield(t('Authored on'), 'date', $edit->date, 20, 25);
$output .= '<div class="authored">';
$output .= form_group(t('Authoring information'), $author);
......@@ -1157,14 +1158,14 @@ function node_form($edit, $error = NULL) {
$output .= form_group(t('Options'), $options);
$output .= "</div>\n";
$extras .= implode('</div><div class="extra">', node_invoke_nodeapi($edit, 'form admin', $error));
$extras .= implode('</div><div class="extra">', node_invoke_nodeapi($edit, 'form admin'));
$output .= $extras ? '<div class="extra">'. $extras .'</div></div>' : '</div>';
}
// Add the default fields.
$output .= '<div class="standard">';
$output .= form_textfield(t('Title'), 'title', $edit->title, 60, 128, $error['title']);
$output .= form_textfield(t('Title'), 'title', $edit->title, 60, 128);
// Add the node-type-specific fields.
......@@ -1192,7 +1193,7 @@ function node_form($edit, $error = NULL) {
$output .= form_submit(t('Preview'));
if (!$error) {
if (!form_get_errors()) {
if ($edit->title && $edit->type) {
$output .= form_submit(t('Submit'));
}
......@@ -1283,7 +1284,7 @@ function node_edit($id) {
/**
* Generate a node preview, including a form for further edits.
*/
function node_preview($node, $error = NULL) {
function node_preview($node) {
// Convert the array to an object:
$node = array2object($node);
......@@ -1325,7 +1326,7 @@ function node_preview($node, $error = NULL) {
$output .= node_view($node, 0);
}
$output .= node_form($node, $error);
$output .= node_form($node);
$name = node_invoke($node, 'node_name');
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => $name)), 'node/add/'. $node->type)));
......@@ -1341,11 +1342,11 @@ function node_submit($node) {
global $user;
// Fix up the node when required:
$node = node_validate($node, $error);
$node = node_validate($node);
// If something went wrong, go back to the preview form.
if ($error) {
return node_preview($node, $error);
if (form_get_errors()) {
return node_preview($node);
}
// Prepare the node's body:
......@@ -1484,8 +1485,8 @@ function node_page() {
}
break;
case t('Preview'):
$edit = node_validate($edit, $error);
print theme('page', node_preview($edit, $error), t('Preview %name', array('%name' => $name)));
$edit = node_validate($edit);
print theme('page', node_preview($edit), t('Preview %name', array('%name' => $name)));
break;
case t('Submit'):
drupal_set_title(t('Submit %name', array('%name' => $name)));
......
......@@ -1035,9 +1035,8 @@ function node_feed($nodes = 0, $channel = array()) {
/**
* Preform validation checks on the given node.
*/
function node_validate($node, &$error) {
function node_validate($node) {
global $user;
$error = array();
// Convert the node to an object, if necessary.
$node = array2object($node);
......@@ -1046,7 +1045,7 @@ function node_validate($node, &$error) {
if (isset($node->title)) {
$node->title = strip_tags($node->title);
if (!$node->title) {
$error['title'] = theme('error', t('You have to specify a valid title.'));
form_set_error('title', t('You have to specify a valid title.'));
}
}
......@@ -1081,7 +1080,7 @@ function node_validate($node, &$error) {
$node->uid = $account->uid;
}
else {
$error['name'] = theme('error', t("The name '%u' does not exist.", array ('%u' => $node->name)));
form_set_error('name', t("The name '%u' does not exist.", array ('%u' => $node->name)));
}
// Validate the "authored on" field.
......@@ -1089,7 +1088,7 @@ function node_validate($node, &$error) {
$node->created = strtotime($node->date);
}
else {
$error['date'] = theme('error', t('You have to specifiy a valid date.'));
form_set_error('date', t('You have to specifiy a valid date.'));
}
}
else {
......@@ -1105,8 +1104,10 @@ function node_validate($node, &$error) {
}
// Do node-type-specific validation checks.
$result = node_invoke($node, 'validate');
$error = $error + (is_array($result) ? $result : array()) + node_invoke_nodeapi($node, 'validate');
node_invoke($node, 'validate');
node_invoke_nodeapi($node, 'validate');
$node->validated = true;
return $node;
}
......@@ -1114,24 +1115,24 @@ function node_validate($node, &$error) {
/**
* Generate the node editing form.
*/
function node_form($edit, $error = NULL) {
function node_form($edit) {
// Validate the node if we don't already know the errors.
if ($error === NULL) {
$edit = node_validate($edit, $error);
if (!$edit->validated) {
$edit = node_validate($edit);
}
// Prepend extra node form elements.
$form = implode('', node_invoke_nodeapi($edit, 'form pre', $error));
$form = implode('', node_invoke_nodeapi($edit, 'form pre'));
// Get the node-specific bits.
// We can't use node_invoke() because $error and $param must be passed by reference.
// We can't use node_invoke() because $param must be passed by reference.
$function = node_get_module_name($edit) .'_form';
if (function_exists($function)) {
$form .= $function($edit, $error, $param);
$form .= $function($edit, $param);
}
// Append extra node form elements.
$form .= implode('', node_invoke_nodeapi($edit, 'form post', $error));
$form .= implode('', node_invoke_nodeapi($edit, 'form post'));
$output .= '<div class="node-form">';
......@@ -1140,8 +1141,8 @@ function node_form($edit, $error = NULL) {
if (user_access('administer nodes')) {
$output .= '<div class="admin">';
$author = form_textfield(t('Authored by'), 'name', $edit->name, 20, 60, $error['name']);
$author .= form_textfield(t('Authored on'), 'date', $edit->date, 20, 25, $error['date']);
$author = form_textfield(t('Authored by'), 'name', $edit->name, 20, 60);
$author .= form_textfield(t('Authored on'), 'date', $edit->date, 20, 25);
$output .= '<div class="authored">';
$output .= form_group(t('Authoring information'), $author);
......@@ -1157,14 +1158,14 @@ function node_form($edit, $error = NULL) {
$output .= form_group(t('Options'), $options);
$output .= "</div>\n";
$extras .= implode('</div><div class="extra">', node_invoke_nodeapi($edit, 'form admin', $error));
$extras .= implode('</div><div class="extra">', node_invoke_nodeapi($edit, 'form admin'));
$output .= $extras ? '<div class="extra">'. $extras .'</div></div>' : '</div>';
}
// Add the default fields.
$output .= '<div class="standard">';
$output .= form_textfield(t('Title'), 'title', $edit->title, 60, 128, $error['title']);
$output .= form_textfield(t('Title'), 'title', $edit->title, 60, 128);
// Add the node-type-specific fields.
......@@ -1192,7 +1193,7 @@ function node_form($edit, $error = NULL) {
$output .= form_submit(t('Preview'));
if (!$error) {
if (!form_get_errors()) {
if ($edit->title && $edit->type) {
$output .= form_submit(t('Submit'));
}
......@@ -1283,7 +1284,7 @@ function node_edit($id) {
/**
* Generate a node preview, including a form for further edits.
*/
function node_preview($node, $error = NULL) {
function node_preview($node) {
// Convert the array to an object:
$node = array2object($node);
......@@ -1325,7 +1326,7 @@ function node_preview($node, $error = NULL) {
$output .= node_view($node, 0);
}
$output .= node_form($node, $error);
$output .= node_form($node);
$name = node_invoke($node, 'node_name');
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => $name)), 'node/add/'. $node->type)));
......@@ -1341,11 +1342,11 @@ function node_submit($node) {
global $user;
// Fix up the node when required:
$node = node_validate($node, $error);
$node = node_validate($node);
// If something went wrong, go back to the preview form.
if ($error) {
return node_preview($node, $error);
if (form_get_errors()) {
return node_preview($node);
}
// Prepare the node's body:
......@@ -1484,8 +1485,8 @@ function node_page() {
}
break;
case t('Preview'):
$edit = node_validate($edit, $error);
print theme('page', node_preview($edit, $error), t('Preview %name', array('%name' => $name)));
$edit = node_validate($edit);
print theme('page', node_preview($edit), t('Preview %name', array('%name' => $name)));
break;
case t('Submit'):
drupal_set_title(t('Submit %name', array('%name' => $name)));
......
......@@ -129,7 +129,7 @@ function page_view($node, $teaser = FALSE, $page = FALSE) {
/**
* Implementation of hook_form().
*/
function page_form(&$node, &$error) {
function page_form(&$node) {
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('page', $node));
}
......
......@@ -129,7 +129,7 @@ function page_view($node, $teaser = FALSE, $page = FALSE) {
/**
* Implementation of hook_form().