For an English speaker (like me) perhaps it's easiest to think of different translations for these verbs. For example think of helfen as meaning 'to give help' rather than 'to help'. Then Ich helfe dir, translates as "I give help to you," and the dative dir makes much more sense. Similarly, think of gefallen as meaning 'to please', or better 'to be ...
I recently came across a German sentence: -
"Gefallen Ihnen die Rosen nicht?"
I know that Gefallen is a Dativ verb, but shouldn't the sentence be :
"Gefallen Sie die Rosen nicht?"
No, in this case Ihnen is the dative form of the polite address Sie (singular).
The rough translation of the above sentence (according to me) is: -
In your example, "ich helfe dir" you are being helped by "I", so to speak.
Similarly, consider the sentence "Die Rosen gefallen dir." Here, the roses are pleasing "to you."
For your question, the word order is arranged to form a question. However, "Ihnen" (the dative form of formal you) still translates to &...