Giving salutation before the completion of the Prayer is a case of addition in the Prayer. So whoever gives the salutation before the completion of the Prayer deliberately, then his prayer is nullified.
If, however, it is done due to forgetfulness, and he does not remember this until after a long time then he should repeat his prayer again. If he remembers a short time later, such as after two or three minutes, then he should complete his prayer and salutation, and then prostrate for forgetfulness, and then give salutation (again).
The proof for this is the hadeeth of Aboo Hurairah (radiallahu anhu) who said that,
“The Prophet (sallallahu alaihe wa-sallam) lead them in the Zuhr prayer or the ‘Asr prayer and gave the salutation after two rak’ahs. Then he departed quickly from one of the doors of the mosque, and the people were saying that the prayer had been decreased. The Prophet (sallallahu alaihe wa-sallam) meanwhile, stood by a piece of wood placed in the mosque, leaning against it, as if he was angry. So a man stood and said, ‘O Messenger of Allah, have you forgotten or has the prayer been reduced?’ So the Prophet, (sallallahu alaihe wa-sallam) said, ‘I did not forget nor has it been reduced.’ So the man said, ‘Rather you have indeed forgotten.’ So the Prophet (sallallahu alaihe wa-sallam) said to the Companions, ‘Is what he is saying true.’ They said, ‘Yes.’ So the Prophet (sallallahu alaihe wa-sallam) went forward and prayed what remained of his prayer, then he gave the salutation, then he prostrated twice, then he gave the salutation.” [Agreed upon]
And if the Imam gives the salutation before completion of his prayer and there are some followers who missed part of the prayer and who stand up to make up what they had missed, and then the Imam remembers that there is something incomplete in his prayer that he has to make up for, so he stands to complete that - then in this case the followers who have already stood to complete what they missed have a choice between continuing to make up what they missed and then prostration for forgetfulness, and between returning to following the Imam - and when he performs the salutation to complete what they had missed - and then to prostrate for forgetfulness after giving the salutation, and this is more right and is more prudent.
 Reported by Al-Bukhari (Eng. Trans. vol. 2, nos. 318-321) and (Muslim Eng. Trans. vol. 1, nos. 1182-1186).
Please write: COMMENT in this box to verify that you are human