Daydreaming is the stream of consciousness that detaches from current external tasks when attention drifts to a more personal and internal direction. This phenomenon is common in people's daily life shown by a large-scale study in which participants spend 47% of their waking time on average on daydreaming. There are various names of this phenomenon including mind wandering, fantasy, spontaneous thoughts, etc.
Shaitan tries to divert the attention of people from the prayer to other things, that it is why, it is recommended to say after Takbiratul Ehraam when you start the prayer (A'ootho Billah Minashshaytan Arrajeem)أعوذ بالله من الشيطان الرجيم
Your prayer is still valid even if you think outside the prayer, but the reward will be decreased as the Hadeeth says: The prayer will be raised to the sky as much as the attention is in the prayer. لا يرفع للعبد من صلاته إلا ما وعى
It is very important to know while you are praying that:
You are in front of Allah and you are talking to him.
We need to remember our sins and be very humble in front of Allah, seeking forgiveness.
Also we need to remember our definite end in this life and our next life in our grave then our final place in the hereafter where it will be either Paradise or Hellfire God forbid. Remembering these facts will make our prayer more dedicated and our mind more concentrated on the Prayer.