My problem:
I have a custom node type, where I have tags required.
If I try to submit the node without tags, it saves (which it shouldn't), and gives the following error after saving:
Notice: Undefined index: tid i taxonomy_field_is_empty() (linje 1395 af /var/www/drupal7/modules/taxonomy/taxonomy.module).
I have several other required fields in the same node type.
If more is missing, they produces something like "Field x is required. Please fill out" (or something like that), and below that list, the same error will show up, instead of a "Tags is required. Please fill out". If you chose some tags after this message, it simply doesn't save. But it saves if you go back and edit afterwards.
Summary of my problem:
1: It's possible to submit a node with required tag fields, even if no tags have been chosen.
2: If other things are missing in the form so it can't submit, and you fix it and then add some tags, they doesn't save when the rest is saved.
3: Errormessage isn't like the other errormessages, but more like error in code, instead of notice about missing form items.
Info about my installation:
I run the following:
Drupal 7.10
tagging 7.x-3.3
Full vocabulary is shown as suggested tags, since it's a rather small vocabulary.
I'm unsure if it's the same issue as here: http://drupal.org/node/1389312
I have Field group 7.x-1.1 installed and it is used on this node type.
To be sure that it wasn't core taxonomy module that created this error, I tried deactivating this module, and tried to reproduce, which I couldn't. Activated the module again, and tried once more. Same error as earlier. Every time the tags are not chosen before trying to save.
If the tags are added as they should be, before submitting, there is no problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | tagging-fix-taxonomy-empty-field-1429258.patch | 1.57 KB | alexverb |
Comments
Comment #1
alexverb commentedI can confirm this bug. Looks like it might have something to do with taxonomy after all. As described in: http://drupal.org/node/709964.
I tried the patch but that gives me some other warnings on save if tagging field is empty:
Comment #2
alexverb commentedFixed it. Can't blame taxonomy for expecting a tid. Tagging was sending over an wrong structured array. Just emptying out that array if there is no actual input fixed the problem.
Comment #3
eugenmayer commentedThank you Mywebmaster for the work.
Interesting, we were hunting that one for some time AFAIR.Will need to double check this. We need 2 or more to vaildate that fix works for them in producation, i would expect sideeffects could happen here
Comment #4
alexverb commentedI wouldn't really expect many side effects. Because it just returns TRUE on an empty field because it's not an array and Drupal will handle the rest. Offcourse I'm not saying that my fix is the right one. I'm shure there are much better ways to handle it.
Comment #5
eugenmayer commentedcurrently dont have time to really dive into this. If someone has some spare time, i would be glad to have someone with deeper d7 insight her. Thanks!
Comment #6
soelver commentedTried the patch, and it worked for some of the problem.
I don't get the error message anymore, but I can still submit my form without the required tags. Only difference is, that it doesn't give me an error message. If other required fields are missing, and I try to submit, they give me a warning, and leads me to the missing field. But that removes the tags if any were chosen.
So I tried these steps:
1. Fill all required fields except tags
2. Submit = Works without any warnings of my missing tags (which is wrong, since tags are required)
1. Fill all required fields, including tags, except title
2. Submit = Warning about missing title, prompted to fill in. Tags are removed when this happens.
3. Submit again = Saves without warning, no tags (which is wrong, since tags are required)
1. Fill all required fields
2. Submit: Works fine (Which it also did before)
So, not quite enough to solve the problem.
I must say, that I added the patch by hand.
It's possible, that I've made a mistake, but since the error doesn't come up anymore, and everything else is working, I think it's done properly.
Comment #7
soelver commentedUhm.. the other code, where do that fit in?
I just used the patch.
Comment #8
alexverb commentedYou don't need that code. I just showed it to explain what happens on a taxonomy_field_is_empty() call. And looking back at the code of the patch I may have overlooked the values that were allready saved. I'll look back into it when I got some spare time.
Comment #9
eugenmayer commentedthanks for helping!
Comment #10
soelver commented#8 Thank you for clearing that up :)
I wish I could help myself, but I don't have the skills :(
Any help will be great, so I'll just put this on hold for now, and move on to something else, until you have the time to look into it. Thank you for the time you've spend on it already, Mywebmaster :)
And thank you for a great module, EugenMayer. I love it.
Comment #11
IWasBornToWin commentedI'm getting similar error when editing the field. Although, it appears the terms are being saved. I tried to apply the patch in #2 but it said unable to apply.
Comment #12
IWasBornToWin commentedSorry, here's the error - Notice: Undefined index: nid in tagging_field_widget_form() (line 87 of /sites/all/modules/tagging/tagging.field.inc).
Comment #13
IWasBornToWin commentedActually, after saving I also get the tid error as well.
Comment #14
IWasBornToWin commentedAny suggestions?
Comment #15
eugenmayer commentedIam running out of time ATM, so please dont wait for my advice.
Comment #16
alexverb commentedThe patch definatly removes the tid error. But it seems the bug that causes an empty required tagging field to pass validation is located somewhere else. Because without the patch it also passes the required field validation.
The bug that causes the tagging field to lose its value whenever another field fails validation is still a mystery to me. It may have something to do with the fact the module is using ['#value'] in the function tagging_taxonomy_autocomplete_validate($element, &$form_state). Shoudn't it be validating the $form_state['values'] instead?
I'm also low on spare time but this bug stays on my TODO list.
Comment #17
eugenmayer commentedMywebmaster, thanks for helping out and being verbose on the analysis. Iam not sure how things work in D7, as there is no longer a separation beweetn "cck fields" and form fields, which are working differently on validation in D6. In D6, tagging uses the form field and actually replaces + hides the original one, while still passing the values in the original FAPi element. This enables tagging to not implement any submit / validate handler, as the one of taxonomy are used. Now with D7 we have
- fields and form fields, i guess we are dealing with a form field here
- we have a complete different taxonomy implementation which is rather based on fields, right?
- we are failing using the core validate methods due to wrong isEmpy implementations of the FAPI element or wrong validate handlers
The last point needs to be investigated, but i rather suggest we need someone D7 experienced to give us an best-practice advice here.
Comment #17.0
eugenmayer commentedEdited some text, to make it clearer what I was trying to explain :)