Comments

wferrell343’s picture

Priority: Normal » Critical

I really need this feature as well.

earwax’s picture

Yup, I also need this. I have a lot of required fields in my form. If I can't save a draft, then the user might as well as finish my form!

rooby’s picture

Title: What about required fields » Allow saving drafts with missing required fields
Version: 7.x-1.4 » 7.x-1.x-dev
Category: support » feature
Priority: Critical » Normal
Status: Active » Needs review
StatusFileSize
new2.21 KB

Here is a patch that makes it so that:
1. You can save as draft without filling in required fields.
2. Required fields are still marked with a red asterisk as usual.
3. Required fields are still required before you can publish a node.
4. Other forms of validation still apply when saving as draft. For
example, file upload size or min & max values for integer fields.

Point 4 is the part where most other solutions fall down. Other approaches that remove all validation (not just required validation) introduce potential security issues and are not recommended.

If the module maintainer would prefer that this feature be a setting that can be enabled/disabled, I can also add that.

I will add a tests for this soon too.

The patch is for 7.x-1.x-dev but will also apply to 7.x-1.4.

This patch was sponsored by Ferrell Systems LLC (wferrell343).

rooby’s picture

StatusFileSize
new2.13 KB

Here is a new version.
The only change is a minor change to a comment that was wrong.

beeradb’s picture

I spent about 30 minutes with this patch and honestly it looks great. It works surprisingly well with panels / panelizer which was one of my major concerns.

This gets a +1 from me. It'd be nice to get at least one more review on this before moving to RTBC though.

alan d.’s picture

This could be enhanced using something like this:

+  $form['actions']['draft']['#bypass_validation'] = 1;

-    if ($form_state['triggering_element']['#value'] == $element['actions']['draft']['#value']) {
+    if (!empty($form_state['triggering_element']['#bypass_validation'])) {

So then users could piggy back this to prevent validation on other buttons:

  $actions['delete']['#bypass_validation'] = TRUE;
rooby’s picture

@Alan D.:
Good point, I can see the use cases there.

I will look into that when I do the tests & admin setting (soonish).

Karthick_s’s picture

'#limit_validation_errors' => array() would mean not to validate anything why cant we use this

rooby’s picture

'#limit_validation_errors' => array() would mean not to validate anything why cant we use this

Because we aren't trying to remove all validation and because that is not really what that form API feature/hack is for.
Draft content should still conform to any non-required validation.

See the title of this issue: #370537: Allow suppress of form errors (hack to make "more" buttons work properly)
It is a hack for a specific use case and we should try to make things as non-hackish as possible.

Also see:
#763376-166: Not validated form values appear in $form_state, which is in response to #763376-165: Not validated form values appear in $form_state, and refers to #763376-3: Not validated form values appear in $form_state.

Which basically means it is a potential security issue, which in the case of ajax add more buttons (the intended use case) is mitigated by the fact that those ajax calls aren't actually saving the potentially insecure data, which will be properly validate before the real submit.

In this case the data will actually be saved so it really needs to run through normal validation processes.

This use case (skipping just the required validation) does not pose a security issue.

I did a fair bit of thinking on this one and this was the only way I could see to do it properly, with no ill effects.

rattusrattus’s picture

I've just been testing this patch out and I think I've identified a bug:

I created a new node and clicked 'save as draft' with required fields - behaved as expected.

When I went to go and delete this node it wouldn't let me without entering the required fields.

alan d.’s picture

This is not a bug, this is how Drupal normally works :(

However if comments in #8 are accepted, you can use this to bypass validation and delete the node if you form alter and add the same flag. I'm using this logic on a couple of different node types.

$form['actions']['delete']['#bypass_validation'] = 1;
rooby’s picture

Here is a new version of the patch in #4.

It adds Alan's suggestion of a #skip_required_validation property.
Any button with that property set to TRUE will skip required validation.

It also adds #skip_required_validation to Preview & Delete buttons.
Delete is definitely required.

I have also added a note to the README for developers, to make them aware of the new property.

I am doing another version now that adds settings for this.
I didn't do it all in one go as this next one will depend on the patch in #1409000-7: Provide an option to enable "save draft" feature per content type being applied first, which some testers might not want to do.

rooby’s picture

This patch is the patch from #12 with the addition of a setting to enable/disable the functionality.
It is disabled by default so that users on previous versions don't have the functionality change unexpectedly.

You need to apply the patch at #1409000-7: Provide an option to enable "save draft" feature per content type before you apply this patch.

rooby’s picture

Last one (hopefully :)).

This one is #13 but cleanup of variables has been added and tests have been added.
It applies after the patch in #1409000-8: Provide an option to enable "save draft" feature per content type

gumdal’s picture

Hi rooby,

I am unable to apply your patch. I checked out the latest 7.x-1.x and then saw that it already has your patch #8 from issue 1409000 (merged on 2nd Dec 2012), so I skipped applying that patch and tried to directly apply your patch #14 from this post. Seems that the patch fails with the following error:

"Patch format detection failed."

Then I tried to apply patch with the following:

"git apply --whitespace=fix save_draft-per_content_type-1409000-8.patch"

Even this fails with errors. Am I doing anything wrong?

I also tried to rollback the branch 7.x-1.x to the tag 7.x-1.4 (7070bb796d0e8a27d90e819f93ea292c83d82b12) and tried to apply patch #8 of 1409000 and then patch #14 from here, even this did not work.

Any suggestions?

Thanks.

rooby’s picture

Damn. I made it on a windows machine in a linux VM.
I might have accidentally saved it with windows line endings at some point.
Ill make another one against the latest dev.

rooby’s picture

OK I found the problem.
It was a problem with the patch that was recently committed.

If you apply the patch in #1409000-12: Provide an option to enable "save draft" feature per content type then you will be able to apply the patch in #14 of this issue.

gumdal’s picture

StatusFileSize
new30.41 KB

Now am able to patch the 2 files as you have mentioned, but it seems that the functionality is not working for me.

You can see the errors which am getting from my website when am trying to "Save as draft" a half done work, like this:

Error

Now to make sure that I have indeed successfully patched the 2 files, I double checked a patch comment which you have added in #14
"// Add a flag to buttons that can skip required validation."

In the file save_draft.module of my server. It does appear there too which means that the patches were successfully applied. I don't know why it is not working for me. Anything else am supposed to do?

Thanks

rooby’s picture

You have to enable the feature on your content type edit page.

Hopefully that's all it is.

gumdal’s picture

Status: Needs review » Fixed

Yes, there is a "Skip required validation" in Admin -> structure -> {Content Type} which I had missed out. Also it is working as expected. Thanks for this important feature.

earwax’s picture

Status: Fixed » Patch (to be ported)

I am not sure how the whole tracking thing and merging of a patch works, but should this ticket really be "Fixed" and closed? Wouldn't we want this to be in the module in the next update? I'm guessing the appropriate status would be "patch (to be ported)". Or maybe it needs more testing? I just don't want this great feature to be missed out by the maintainers since it seems pretty important.

rooby’s picture

Status: Patch (to be ported) » Needs review

See here for more info on statuses - http://drupal.org/node/156119

If it works for gumdal and others then it should go to reviewed and tested by the community.
Then a module maintainer can come review and commit it, then it is fixed.

A person should not set RTBC on their own patch so ill put it back to needs review.

arrow’s picture

Status: Needs review » Reviewed & tested by the community

Applied the patch as mentioned in #17 and then the patch from #14. Everything seems to be working. Thanks rooby!

earwax’s picture

I can successfully apply the patch from #17. But when I then apply the patch from #14, I get

patching file README.txt
patching file save_draft.install
patching file save_draft.module
Hunk #1 succeeded at 66 with fuzz 2 (offset -21 lines).
Hunk #2 FAILED at 144.
Hunk #3 succeeded at 103 with fuzz 2 (offset -88 lines).
1 out of 3 hunks FAILED -- saving rejects to file save_draft.module.rej
patching file save_draft.test
Hunk #1 FAILED at 101.
1 out of 1 hunk FAILED -- saving rejects to file save_draft.test.rej

This can't be right? I am patching from the save_draft-7.x-1.4 version.

rooby’s picture

Nope, the patches should be applied to latest dev (the version of this issue)

You can get it from http://drupal.org/node/912106

earwax’s picture

Thanks! Patching against the development version worked. My fields have a lot of required in them and this allowed the user to "save as draft", including "holding" onto uploaded files. This is great!

pooyajavan’s picture

rooby’s picture

@pooyajavan:

I have replied in that new issue you opened also, but I think the patch should be a direct backport to drupal 6 of the patch in #14 of this issue and it can just be posted in here, noting that it is a drupal 6 version.

You can just add the the end of the file name D6-do-not-test (if the test bot tries to test the patch thinking it is a drupal 7 one it will fail).

Note that we will also need a drupal 6 version of the patchs in #1409000: Provide an option to enable "save draft" feature per content type (#8 and #12) - but I also noted that in the new issue you opened, which can also go in that issue with the D6-do-not-test part at the end of the file name (before the file extension - see http://drupal.org/node/332678#skipping)

kiricou’s picture

Really thank you for this patch,

It works for me,
but I open a new issue for a use case with module Workflow

Sim

glenshewchuck’s picture

I applied the patches from #14 and #17 and it works great for skipping required fields, they even work on field collection fields.

However, If I use the "addressfield" module in a field collection then any required field in that field collection stays required even if the address field is not required.

So for example: if I have a field collection (collection1) and it has two fields: 1. SSN (required) and 2. Address1 (via addressfield module but not required) the SSN stays required. I'm looking into what the addressfield module is changed but have not found it yet. Any ideas?

field_collection1
- SSN1:
---text field type
---required
- Address1:
---addressfield type
---not required

(I'm working on a fresh 7.22 install for testing)

GemVinny’s picture

I got this working using the patches suggested, although I can't get it working with the Field Validation module. Has anyone else had the same problem?

Thanks
Gem

dooug’s picture

I applied these patches and confirmed that the basic use case is working. Thanks!

I have not tested with Address fields or Field Validation module.

deanflory’s picture

I'm getting these patch errors when applying it to the 7.x-1.4.

patch < save_draft-per_content_type-1409000-12_2.patch (SUCCEEDED NO PROBLEM)

patch < save_draft-required_fields-1786442-14.patch
patching file README.txt
patching file save_draft.install
patching file save_draft.module
Hunk #1 succeeded at 66 with fuzz 2 (offset -21 lines).
Hunk #2 FAILED at 123.
Hunk #3 succeeded at 110 with fuzz 2 (offset -88 lines).
1 out of 3 hunks FAILED -- saving rejects to file save_draft.module.rej
patching file save_draft.test
Hunk #1 FAILED at 101.
1 out of 1 hunk FAILED -- saving rejects to file save_draft.test.rej

There is no dev version available on the project page. I was only able to find individual file commits, trying that now, but obviously not very efficient.

deanflory’s picture

Here's my patching results WITH the latest individual file commits copied over the latest official release:
save_draft.js
save_draft.module
save_draft.test

patch < save_draft-per_content_type-1409000-12_2.patch (SUCCEEDED NO PROBLEM)

patch < save_draft-required_fields-1786442-14.patch
patching file README.txt
patching file save_draft.install
patching file save_draft.module
Hunk #1 FAILED at 87.
Hunk #2 FAILED at 144.
Hunk #3 FAILED at 198.
3 out of 3 hunks FAILED -- saving rejects to file save_draft.module.rej
patching file save_draft.test
Hunk #1 FAILED at 101.
1 out of 1 hunk FAILED -- saving rejects to file save_draft.test.rej

So, even more failures.

rooby’s picture

Thanks for your patience everyone.

This has been committed to dev.

rooby’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed
rooby’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Fixed » Patch (to be ported)

Probably should support the drupal 6 people.

Renee S’s picture

Thanks rooby!

johnhanley’s picture

+1 on this patch for Drupal 7. Validation override works well and is a timely addition to this already excellent module.

Recommend pushing this latest dev snapshot for release.

ashzade’s picture

I can't get this to work. I have the option turned on for my content type and if I DPM $form, I can see that skip_validation is set to TRUE. When I try to Save as Draft, the form wants me to complete the required fields. Am I missing something?

liborvanek’s picture

Unfortunatelly this doesn't work with Clientside validation enabled.
Clientside validation needs to be turned off.

charles belov’s picture

Will this play well with Workbench Moderation?

kirc0060’s picture

Status: Patch (to be ported) » Needs work

The patch applied to dev allows users to circumvent required fields by saving to draft on a node edit page and then publishing from admin/content (to replicate, check the draft node, select "Publish selected content" under "Update options," and "Update")

alan d.’s picture

@kirc0060

On 7.x or 6.x? If 7.x, change to a Major Bug report against the 7.x branch.

kirc0060’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Category: Feature request » Bug report
Priority: Normal » Major
robin.ingelbrecht’s picture

The "Skip required" field option doesn't work for field collections. I still have to fill out the required fields in my field collection

dblankman’s picture

The skip required field is working, but it seems that there is only one save draft, that5 is, if you save a draft, there does not seem to be a away to do another draft save. Am I missing something.

dblankman’s picture

The skip required field is working, but it seems that there is only one save draft, that5 is, if you save a draft, there does not seem to be a away to do another draft save. Am I missing something.

brewerkr’s picture

Same as #48. Once "save a draft" is clicked, all validation is lost from then on out. How can it be skipped only for saving a draft and not shut off altogether once draft is selected?
*Update* - I think I just misunderstood the functionality and didn't realize that Publish still did validation (or it wasn't doing it before in my testing but is now). Anyway, I'm happy now and thanks for this!

pravin ajaaz’s picture

Status: Needs work » Fixed

I believe this functionality is working as it should be.

pravin ajaaz’s picture

Please re-open with more details on the issue

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

makbuk’s picture

Issue summary: View changes

In my form I use Clientside validation, my users need the ability to save draft version (with empty required fields). Is it possible to get around Clientside validation?

rooby’s picture

@makbuk, it is probably possible but that should have its own ticket.

It may also be preferable to handle that in the clientside validation module instead of this module.

mahpari’s picture

Hello Experts,

I need same feature for Drupal 8 so editors will be able to save draft without filling required fields. Is there any solution please!?

Thanks
Mah Pari

unsettlingtrend’s picture

I don't supposed you came across anything for D8, @mahpari?

rooby’s picture

For D8 discussion re D8 and the save draft module, see #2220659: Drupal 8 version, Drupal 9 version