I've made a patch to save forms with empty required fields (e.g. file fields, multigroups, unlimited fields and ...)

Comments

pooyajavan’s picture

Here's the patch.

rooby’s picture

Version: 6.x-1.8 » 6.x-1.x-dev
Status: Closed (fixed) » Needs work

New features go against the 6.x-dev version.
Is this marked as closed (fixed) for a reason? I assume it should be needs review.

At first glance I see a few problems:

1.

+++ b/save_draft.module
@@ -80,3 +81,39 @@ function save_draft_validate($form, &$form_state) {
+function _save_draft_remove_required(&$element) {
+  unset($element['#needs_validation']);
+  foreach (element_children($element) as $key) {
+    _save_draft_remove_required($element[$key]);
+  }

This is bad because it skips more validation than just the required validation.
It also skips the maxlength check and whether or not illegal choices have been entered for options fields. Both of these things could result in problems.

I recommend using the solution from the D7 patch in #1786442-14: Allow saving drafts with missing required fields - Set the #required attribute to FALSE.

2.
It disables validation all the time, instead of adding a setting that admins can configure (point 3 continues on from this).

3.

+++ b/save_draft.module
@@ -80,3 +81,39 @@ function save_draft_validate($form, &$form_state) {
+/**
+ * Implementation of hook_form_alter() for node_type_form
+ */
+function save_draft_form_node_type_form_alter(&$form, $form_state) {
+  // Also add option to node settings form in the admin settings.
+  if (isset($form['identity']['type'])) {
+    $form['workflow']['save_as_draft'] = array(
+      '#type' => 'radios',
+      '#title' => t('Save As Draft'),
+      '#default_value' => variable_get('save_as_draft_'. $form['#node_type']->type, 0),
+      '#options' => array(t('Disabled'), t('Enabled')),
+    );
+  }

This should not be part of this patch (also it doesn't do anything with the save_as_draft settings anywhere else so the setting does not do anything currently.

This patch should have the skip validation functionality and an option on the node settings form for "Skip required validation" (as per the patch in #1786442-14: Allow saving drafts with missing required fields for drupal 7.

The part you have actually is a part of a different issue, see #1409000-8: Provide an option to enable "save draft" feature per content type and also the add-on to that #1409000-12: Provide an option to enable "save draft" feature per content type.
So you will also need a drupal 6 patch for #1409000: Provide an option to enable "save draft" feature per content type that combines the patches in comments #8 and #12 of that issue as well replacing the save_as_draft option from this patch with the save_draft_skip_required option (along with a check like if (variable_get('save_draft_skip_required_' . $form['#node']->type, FALSE)) { in your hook_form_alter() as per the patch in #1786442-14: Allow saving drafts with missing required fields

Really, you just need drupal 6 versions of the patches in #1786442-14: Allow saving drafts with missing required fields and #1409000-8: Provide an option to enable "save draft" feature per content type + #1409000-12: Provide an option to enable "save draft" feature per content type that are as identical to the drupal 7 versions as possible aside from whatever differences there are from drupal 6 to 7.
There is also no reason you couldn't put them in the existing drupal 7 issues because they are addressing the same issue in both versions and they should just be direct backports of those patches to keep consistency between versions.

rooby’s picture

Issue summary: View changes

Grammatical errors

rooby’s picture

Issue summary: View changes
Status: Needs work » Closed (duplicate)
Related issues: +#1786442: Allow saving drafts with missing required fields

Marking as duplicate of #1786442: Allow saving drafts with missing required fields as that issue is now to port the drupal 7 solution to drupl 6.