Index: docs/developer/examples/node_example.module
===================================================================
RCS file: /cvs/drupal/contributions/docs/developer/examples/node_example.module,v
retrieving revision 1.18
diff -u -r1.18 node_example.module
--- docs/developer/examples/node_example.module	14 Aug 2006 14:30:50 -0000	1.18
+++ docs/developer/examples/node_example.module	17 Dec 2006 18:22:23 -0000
@@ -113,7 +113,7 @@
     '#type' => 'textfield',
     '#title' => check_plain($type->title_label),
     '#required' => TRUE,
-    '#default_value' => $node->title,
+    '#default_value' => isset($node->title) ? $node->title : NULL,
     '#weight' => -5
   );
   // We want the body and filter elements to be adjacent. We could try doing
@@ -123,21 +123,21 @@
   $form['body_filter']['body'] = array(
     '#type' => 'textarea',
     '#title' => check_plain($type->body_label),
-    '#default_value' => $node->body,
+    '#default_value' => isset($node->body) ? $node->body : NULL,
     '#required' => FALSE
   );
-  $form['body_filter']['filter'] = filter_form($node->format);
+  $form['body_filter']['filter'] = filter_form(isset($node->format) ? $node->format : NULL);
 
   // Now we define the form elements specific to our node type.
   $form['color'] = array(
     '#type' => 'textfield',
     '#title' => t('Color'),
-    '#default_value' => $node->color
+    '#default_value' => isset($node->color) ? $node->color : NULL
   );
   $form['quantity'] = array(
     '#type' => 'textfield',
     '#title' => t('Quantity'),
-    '#default_value' => $node->quantity,
+    '#default_value' => isset($node->quantity) ? $node->quantity : NULL,
     '#size' => 10,
     '#maxlength' => 10
   );
@@ -154,13 +154,22 @@
  *
  * Errors should be signaled with form_set_error().
  */
-function node_example_validate(&$node) {
+function node_example_validate($node) {
   if ($node->quantity) {
     if (!is_numeric($node->quantity)) {
       form_set_error('quantity', t('The quantity must be a number.'));
     }
   }
-  else {
+}
+
+/**
+ * Implementation of hook_submit().
+ *
+ * If our "quantity" field is empty (e.g. an empty string),
+ * make it zero before inserting into the database.
+ */
+function node_example_submit(&$node) {
+  if (empty($node->quantity)) {
     // Let an empty field mean "zero."
     $node->quantity = 0;
   }
@@ -257,5 +266,3 @@
   $output .= '</div>';
   return $output;
 }
-
-?>
