وَمَنْ أَرَادَ الدُّخُولَ فِي صَلَاةِ غَيْرِهِ يَحْتَاجُ إِلَى نِيَّتَيْنِ: نِيَّةِ الصَّلَاةِ، وَنِيَّةِ الْمُتَابَعَةِ.
Meaning: Whoever wishes to enter another person’s prayer needs two intentions: the intention for the prayer and the intention to follow.
The first specifies the prayer; the second establishes the follower’s relationship to the imam.