wa-ʿalaykum al-salām wa-raḥmatu llāh wa-barakātuh!
You have raised an important and worthy question concerning the Prayer of Gratitude. In this connection a few points deserve to be mentioned.
First of all, one must realise that at every moment we are encompassed by the innumerable favours of Allah, Exalted is He. Our five obligatory prayers, the confirmed Sunnah and other nawāfil, and the rest of our acts of worship – all of them are expressions of servitude to Him and of gratitude for His bounties. In that sense our whole life ought to be suffused with shukr to Allah.
Nevertheless, when a new blessing is conferred, a good news is received, a great distress is removed, or an important objective is achieved, it is appropriate on such an occasion to give special thanks to Allah, Exalted is He. There are various ways of doing so: uttering al-ḥamdu li-llāh with the tongue, giving ṣadaqah and charity, and performing supererogatory prayer before Allah. Of these, expressing gratitude through prayer is a most excellent form.
If the blessing or joy is minor, one may suffice with saying al-ḥamdu li-llāh and, according to ability, giving some charity. However, should a particular favour be granted, it is better to perform two rakʿahs of nafl. In view of the magnitude and greatness of the blessing, four rakʿahs may also be offered; and if an extraordinary and tremendous success is attained – such as the conquest of a city – then even eight rakʿahs can be performed. There is no harm in this, provided that these numbers are not deemed a fixed or obligatory amount prescribed by the Sharīʿah.
In this matter the practice of the Messenger of Allah, ṣallā Allāhu ʿalayhi wa-sallam, on the day of the conquest of Makkah is especially noteworthy. According to the narration of Umm Hānīʾ, raḍiya Allāhu ʿanhā, on that day he entered her house, performed ghusl and prayed eight rakʿahs. This report is found in Ṣaḥīḥ al-Bukhārī and Ṣaḥīḥ Muslim.
In my view it is nearer to the mark to regard this prayer as one of gratitude and acknowledgement before Allah for the immense blessing and victory of the conquest of Makkah. Because it was prayed at the time of ḍuḥā, some scholars have classified it as ṣalāt al-ḍuḥā. Yet merely because the time coincides it does not follow that its purpose was also that of ṣalāt al-ḍuḥā. It is quite possible that the Prophet, ṣallā Allāhu ʿalayhi wa-sallam, offered it as a prayer of gratitude for that magnificent conquest. A detailed investigation of ṣalāt al-ḍuḥā I shall present on another occasion, in shāʾ Allāh.
Another clarification is necessary. Some people, upon receiving a blessing, take the mere prostration (sajdah) to be the way of giving thanks. To the best of my knowledge there is no clear proof that would establish such a prostration as an independent, legislated act of worship for gratitude. On this basis Imām Mālik, raḥimahu llāh, considered it makrūh to perform a prostration solely for shukr.
In my opinion, the better course for avoiding this difference is that a person should at the very least utter al-ḥamdu li-llāh in thanks to Allah, and if he wishes to do more he should perform two rakʿahs of nafl.
There is a sound reason for this. In two rakʿahs there are four prostrations, and together with them, standing, recitation, bowing and the other adhkār are included. Thus the servant expresses gratitude and servitude to Allah with his whole being and with all the integrals of the prayer.
When a single rakʿah is deficient, then a solitary prostration, bowing or standing is even more deficient; likewise, to designate merely one component as an independent way of expressing thanks is questionable. However, if someone, overwhelmed by intense joy and gratitude upon receiving a mighty favour, should involuntarily fall into prostration, it is hoped that Allah will grant him the reward of his feeling of gratitude. Yet to regard that as a set and prescribed form of worship is not correct.
The upshot of the discourse is that, upon receiving any blessing, offering two rakʿāt of supererogatory ṣalāh in gratitude to Allah, Exalted is He, is a worthy and commendable deed, and performing a sajdat al-shukr is likewise valid. In either case, the servant conveys before Allah, Exalted is He, his humility, servitude and thankfulness. However, to declare any specific number of rakʿāt, particular sūrahs, or a defined posture as obligatory for the ṣalāt al-shukr is incorrect, unless a distinct proof for it is established. Similarly, instead of regarding it as a mandatory or specifically sunan prayer prescribed by the Sharīʿah, it should be observed as a general nafl prayer and as an expression of gratitude.
May Allah, Exalted is He, grant us the ability to appreciate His favours, to offer thanks to Him in every circumstance, and to worship Him with sincerity and love. wa-mā bikum min niʿmatin fa-mina ’llāh.