I am bit confused with the german translation of the English sentence "He gives her a pen". In german language it is "Er gibt ihr einen Stift". Now, we have "einen" because "Stift" is in accusative form. But shouldn't "ihr" be in dative form then and thus "ihrer". Or have I understood it incorrectly? Thanks!
Welcome to German SE! This has already been answered pretty well in the comments, but I'll add an actual answer for good form. Yes, you did correctly identify the accusative object "the pen" and the dative object "her". This can be confusing for English speakers learning German because English does not really distinguish between these cases, instead we only have an object case and use word order or prepositions to tell which noun is is doing what in the sentence. A good rule of thumb is to rephrase the sentence with "to", and whichever noun gets the "to" in front of it gets the dative case. So in English the sentence is "He's giving the pen to her.", the "to" comes before "her", so "her" is in the dative in German. As rules of thumb go in German, this is fairly reliable, but there are the occasional exceptions to look out for. (One such is Ich lehre den Jungen das Klavierspielen, -- "I'm teaching the piano to the boy," but notice that it's den Jungen not dem Jungen.)
I think what's confusing you is that, unlike what you might expect as an English speaker, the accusative form of sie is still sie, it's the dative form ihr that's a cognate to English "her". So to an English speaker the sentence Ich sehe sie, sounds like "I see she," which seems wrong. So I think you're over correcting by making ihr, which is already in the dative, even more dative by adding an -er, but all this does to create a possessive pronoun which is not what is needed here. (I don't know if you've covered possessive pronouns yet, but basically you'd translate ihrer as "hers" as in "The pen is hers.") I hope this helps.