I wanted to do something but have forgotten.
Is this sentence valid? Can I use the past simple with the present perfect in this case?
As another example:
I have wanted to buy something but have forgotten what.
I think your first example should in fact use a different tense from your second.
The first should be:
I wanted to do something but forgot.
You wanted to do it, at some time before now, therefore "wanted" is past tense.
Forgetting it was also in the past - you've evidently remembered it now, or you wouldn't have said anything.
Perfect tense ("have forgotten") would imply that you forgot it and it stayed forgotten, which, again, it didn't.
So you're left with past simple ("forgot").
The second, on the other hand, should be:
I wanted to buy something but have forgotten what.
I'm not really sure whether perfect tense ("have wanted") for the first part is grammatically wrong, but it sounds awkward compared to past simple and past simple is definitely correct, so "wanted" it is.
This time, you evidently still haven't remembered what it was you wanted to buy, so perfect tense ("have forgotten"), for something that happened and stayed that way, is correct.
I believe that I forgot and I have forgotten have the exact same meaning, so both of them are grammarily correct.
If I were you, I would say "I wanted to do something but I forgot" to be safe, but I'm not sure if we can say your way :-)