ﺍﮐﻨﻮﻥ ﮐﻪ ﺷﻤﺎ ﺑﺎ ﻧﺤﻮﻩ ﮐﺎﺭ ﭘﯽ ﺍﭺ ﭘﯽ ﺁﺷﻨﺎ ﺷﺪﻳﺪ٬ ﻭﻗﺖ ﺁﻥ ﺭﺳﻴﺪﻩ ﮐﻪ ﺍﺯ ﺁﻥ ﺩﺍﻧﺶ ﭘﺎﻳﻪ ﺍﯼ ﺍﺳﺘﻔﺎﺩﻩ ﮐﺮﺩﻩ ﻭ ﺭﻓﺘﻪ ﺑﻪ ﺭﻓﺘﻪ ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﯽ ﺑﺎ ﭘﯽ ﺍﭺ ﭘﯽ ﺭﺍ ﺑﻪ ﻃﻮﺭ ﺟﺪﯼ ﺗﺮ ﺩﻧﺒﺎﻝ ﮐﻨﻴﻢ. ﺩﺭ ﻃﻮﻝ ﺍﻳﻦ ﺩﺭﺱ ﻣﺎ ﺗﻼﺵ ﻣﯽ ﮐﻨﻴﻢ ﺍﺯ ﻣﻮﺍﺭﺩ ﮔﻔﺘﻪ ﺷﺪﻩ ﺍﺳﺘﻔﺎﺩﻩ ﮐﺮﺩﻩ ﻭ ﻗﺪﻡ ﺑﻪ ﻗﺪﻡ ﻧﮑﺎﺕ ﺟﺪﻳﺪ ﺭﺍ ﺑﻪ ﺁﻥ ﺍﺿﺎﻓﻪ ﮐﻨﻴﻢ. ﺍﻳﻦ ﺩﺭﺱ ﺑﺎ ﺳﺎﺧﺖ ﻓﺮﻡ ﺩﺭ ﺍﭺ ﺗﯽ ﺍﻡ ﺍﻝ ﺁﻏﺎﺯ ﺷﺪﻩ ﻭ ﻳﺎﺩ ﻣﯽ ﮔﻴﺮﻳﻢ ﮐﻪ ﭼﻄﻮﺭ ﻣﯽ ﺗﻮﺍﻧﻴﻢ ﺍﺯ ﭘﯽ ﺍﭺ ﭘﯽ ﺑﺮﺍﯼ ﮐﺎﺭ ﺑﺎ ﻣﻘﺎﺩﻳﺮ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺗﻮﺳﻂ ﻓﺮﻡ ﺍﺳﺘﻔﺎﺩﻩ ﮐﻨﻴﻢ.
ﺳﺎﺧﺖ ﻓﺮﻡ ﺍﭺ ﺗﯽ ﺍﻡ ﺍﻝ
ﺩﺭ ﺳﺎﺧﺖ ﻳﮏ ﺗﺎﺭﻧﻤﺎﯼ ﭘﻮﻳﺎ ﻳﮑﯽ ﺍﺯ ﻣﻬﻤﺘﺮﻳﻦ ﻣﻮﺍﺭﺩ ﮐﺎﺭ ﺑﺎ ﻓﺮﻡ ﻫﺎﯼ ﺍﭺ ﺗﯽ ﺍﻡ ﺍﻝ ﻭ ﺳﺎﻣﺎﻥ ﺩﺍﺩﻥ ﺩﺍﺩﻩ ﻫﺎﯼ ﺍﺭﺳﺎﻟﯽ ﺍﺯ ﺁﻥ ﺗﻮﺳﻂ ﭘﯽ ﺍﭺ ﭘﯽ ﺍﺳﺖ.
ﺑﺮﺍﯼ ﺍﻧﺠﺎﻡ ﺍﻳﻦ ﻣﻬﻢ ﺩﻭ ﮐﺎﺭ ﺿﺮﻭﺭﯼ ﺍﺳﺖ٬ ﻳﮑﯽ ﺳﺎﺧﺖ ﺧﻮﺩ ﻓﺮﻡ ﻭ ﺩﻳﮕﺮﯼ ﻧﻮﺷﺘﻦ ﮐﺪ ﭘﯽ ﺍﭺ ﭘﯽ ﺑﺮﺍﯼ ﮔﺮﻓﺘﻦ ﻭ ﭘﺮﺩﺍﺯﺵ ﺩﺍﺩﻩ ﻫﺎﯼ ﺍﺭﺳﺎﻟﯽ ﻓﺮﻡ.
ﺍﺯ ﺁﻧﺠﺎﻳﯽ ﮐﻪ ﭘﻴﺶ ﻧﻴﺎﺯ ﺍﻳﻦ ﺩﺭﺱ ﺍﭺ ﺗﯽ ﺍﻡ ﺍﻝ ﻭ ﺁﮔﺎﻫﯽ ﮐﻤﯽ ﺍﺯ ﺳﯽ ﺍﺱ ﺍﺱ ﺍﺳﺖ، ﻣﺎ ﻭﺍﺭﺩ ﺟﺰﻳﻴﺎﺕ ﭼﮕﻮﻧﮕﯽ ﺳﺎﺧﺖ ﻓﺮﻡ ﻧﺨﻮﺍﻫﻴﻢ ﺷﺪ ﺍﻣﺎ ﺩﺭ ﻳﮏ ﻣﺜﺎﻝ ﺷﻤﺎ ﺍﻳﻦ ﻓﺮﻡ ﺭﺍ ﺩﺭ ﺍﺧﺘﻴﺎﺭ ﺧﻮﺍﻫﻴﺪ ﺩﺍﺷﺖ. ﻫﺮ ﻓﺮﻡ ﺍﭺ ﺗﯽ ﺍﻡ ﺍﻝ ﺑﺎ ﺑﺮﭼﺴﺐ <form action="form.php" method="post"> ﺁﻏﺎﺯ ﺷﺪﻩ ﻭ ﺑﺎ </form> ﭘﺎﻳﺎﻥ ﻣﯽ ﭘﺬﻳﺮﺩ. ﺩﺭ ﺩﺍﺧﻞ ﺍﻳﻦ ﻓﺮﻡ ﺩﻭ ﻭﻳﮋﮔﯽ ﻭﺟﻮﺩ ﺩﺍﺭﺩ ﮐﻪ ﺩﺭ ﺯﻳﺮ ﺑﻪ ﺩﻟﻴﻞ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺁﻧﻬﺎ ﺍﺷﺎﺭﻩ ﻣﯽ ﮐﻨﻴﻢ:
- action: ﺍﻳﻦ ﻭﻳﮋﮔﯽ ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﺪ ﮐﻪ ﺩﺍﺩﻩ ﻫﺎ ﺑﻪ ﮐﺪﺍﻡ ﻓﺎﻳﻞ ﮐﻪ ﮐﺪ ﭘﯽ ﺍﭺ ﭘﯽ ﺩﺭ ﺁﻥ ﻗﺮﺍﺭ ﺩﺍﺭﺩ ﺍﺭﺟﺎﻉ ﺩﺍﺩﻩ ﺷﻮﺩ.
- method: ﺍﻳﻦ ﻧﺤﻮﻩ ﻋﻤﻠﮑﺮﺩ ﺩﺭ ﺍﺭﺳﺎﻝ ﺩﺍﺩﻩ ﻫﺎ ﺭﺍ ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﺪ ﮐﻪ ﺩﺭ ﺯﻣﺎﻥ ﺧﻮﺩ ﺑﻪ ﺁﻥ ﺑﻴﺸﺘﺮ ﻣﯽ ﭘﺮﺩﺍﺯﻳﻢ.
ﺩﺭ ﺩﺍﺧﻞ ﺍﻳﻦ ﺑﺮﭼﺴﺐ ﻓﺮﻡ٬ ﺍﻟﻤﺎﻥ ﻫﺎﯼ ﺩﻳﮕﺮﯼ ﻧﻈﻴﺮ textbox ﻭ radio button ﻭ select menu ﻭ ﻏﻴﺮﻩ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﻧﺪ. ﺍﻳﻦ ﺍﻟﻤﺎﻥ ﻫﺎ ﺑﺮﺍﺳﺎﺱ ﻧﻴﺎﺯ ﻭ ﺩﺭ ﺟﺎﯼ ﻣﺸﺨﺺ ﺧﻮﺩ ﻭﺍﻗﻊ ﻣﯽ ﺷﻮﻧﺪ. ﺍﻣﺎ ﻧﮑﺘﻪ ﻣﻬﻢ ﻧﺎﻣﯽ ﺍﺳﺖ ﮐﻪ ﺷﻤﺎ ﺑﺮﺍﯼ ﺁﻧﻬﺎ ﺍﻧﺘﺨﺎﺏ ﻣﯽ ﮐﻨﻴﺪ ﮐﻪ ﮐﺪ ﭘﯽ ﺍﭺ ﭘﯽ ﺑﺎ ﺁﻥ ﻧﺎﻡ ﻫﺎ، ﺁﻧﻬﺎ ﺭﺍ ﺷﻨﺎﺳﺎﻳﯽ ﻣﯽ ﮐﻨﺪ.
ﻣﺸﺨﺼﺎﺕ ﻭﻳﮋﮔﯽ ﻫﺎﯼ method ﺩﺭ ﻓﺮﻡ
ﺩﻭ ﺍﻧﺘﺨﺎﺏ ﺑﺮﺍﯼ ﺍﻳﻦ ﻭﻳﮋﮔﯽ ﻭﺟﻮﺩ ﺩﺍﺭﺩ ﮐﻪ ﺩﺭ ﺯﻳﺮ ﺑﻪ ﺁﻧﻬﺎ ﭘﺮﺩﺍﺧﺘﻪ ﻣﯽ ﺷﻮﺩ:
- GET: ﻭﻗﺘﯽ ﺍﺯ ﺍﻳﻦ ﻭﻳﮋﮔﯽ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﮐﻨﻴﻢ٬ ﺩﺍﺩﻩ ﻫﺎ ﺑﻪ ﺻﻮﺭﺕ ﻧﺎﻡ = ﻣﻘﺪﺍﺭ ﺑﻪ ﻣﺮﻭﺭﮔﺮ ﺷﻤﺎ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺑﻪ ﻃﻮﺭﯼ ﮐﻪ ﺷﻤﺎ ﺩﺭ ﻧﺸﺎﻧﯽ ﻣﺮﻭﺭﮔﺮ ﺧﻮﺩ ﺍﻳﻦ ﺩﺍﺩﻩ ﻫﺎ ﺭﺍ ﻣﺸﺎﻫﺪﻩ ﻣﯽ ﮐﻨﻴﺪ.
ﻣﻮﺍﺭﺩ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺍﻳﻦ ﻭﻳﮋﮔﯽ ﺯﻣﺎﻧﯽ ﺍﺳﺖ ﮐﻪ ﺷﻤﺎ ﺑﻪ ﻃﻮﺭ ﻣﺜﺎﻝ ﻳﮏ ﻓﺮﻡ ﺟﺴﺘﺠﻮ ﻣﯽ ﺳﺎﺯﻳﺪ ﻭ ﮐﺎﺭﺑﺮﺍﻥ ﺍﺯ ﺍﻳﻦ ﻓﺮﻡ ﺑﺮﺍﯼ ﭘﻴﺪﺍ ﮐﺮﺩﻥ ﺍﻃﻼﻋﺎﺕ ﺧﻮﺩ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﮐﻨﻨﺪ. ﺩﺭ ﺍﻳﻦ ﺣﺎﻟﺖ، ﺩﺍﺩﻩ ﻭﺍﺭﺩ ﺷﺪﻩ ﺗﻮﺳﻂ ﮐﺎﺭﺑﺮ ﮐﻪ ﺩﺭ ﺩﺍﺧﻞ ﮐﺎﺩﺭ ﺟﺴﺘﺠﻮ ﻧﻮﺷﺘﻪ ﺷﺪﻩ ﺍﺳﺖ ﺑﻪ ﺻﻮﺭﺕ ﻧﺎﻡ = ﻣﻘﺪﺍﺭ ﺑﻪ ﻣﺮﻭﺭﮔﺮ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﮐﻪ ﺍﻳﻦ ﺩﺭ ﻧﺸﺎﻧﯽ ﻗﺎﺑﻞ ﻣﺸﺎﻫﺪﻩ ﺍﺳﺖ.
ﺧﻮﺑﯽ ﺍﻳﻦ ﮐﺎﺭ ﺍﻳﻦ ﺍﺳﺖ ﮐﻪ ﮐﺎﺭﺑﺮ ﻣﯽ ﺗﻮﺍﻧﺪ ﺍﻳﻦ ﺻﻔﺤﻪ ﺭﺍ ﺑﺮﺍﯼ ﺧﻮﺩ ﻧﺸﺎﻥ ﮔﺬﺍﺭﯼ ﻳﺎ Bookmark ﮐﻨﺪ ﻭ ﻳﺎ ﺑﺎ ﮐﻤﮏ ﺩﮐﻤﻪ ﻋﻘﺐ (Back)٬ ﺑﻪ ﻋﻘﺐ ﺑﺮﮔﺮﺩﺩ.
ﻧﮕﺮﺍﻥ ﻧﺒﺎﺷﻴﺪ! ﺯﻣﺎﻧﯽ ﮐﻪ ﻓﺮﻡ ﺭﺍ ﺑﺎ ﻫﻢ ﺳﺎﺧﺘﻴﻢ، ﺑﻪ ﺻﻮﺭﺕ ﻋﻤﻠﯽ ﺍﻳﻦ ﻣﻮﺭﺩ ﺭﺍ ﮐﺎﻣﻼ ﺧﻮﺍﻫﻴﺪ ﺩﻳﺪ.
ﻧﮑﺘﻪ ۱: ﺑﻪ ﺧﺎﻃﺮ ﭘﺪﻳﺪﺍﺭ ﺷﺪﻥ ﺩﺍﺩﻩ ﻫﺎ ﺩﺭ ﻣﺤﻞ ﻧﺸﺎﻧﯽ ﻣﺮﻭﺭﮔﺮ، ﻣﺎ ﺍﺯ ﻭﻳﮋﮔﯽ get ﺩﺭ ﻣﻮﺍﺭﺩﯼ ﮐﻪ ﺍﻣﻨﻴﺖ ﺩﺭ ﺩﺭﺟﻪ ﺑﺴﻴﺎﺭ ﺑﺎﻻﯼ ﺑﺎﺷﺪ ﺑﻪ ﻫﻴﭻ ﻭﺟﻪ ﺍﺳﺘﻔﺎﺩﻩ ﻧﻤﯽ ﮐﻨﻴﻢ.
ﻧﮑﺘﻪ ۲: ﺩﺭ ﺍﻧﺪﺍﺯﻩ ﻣﻘﺪﺍﺭ ﺩﺍﺩﻩ ﺷﺪﻩ ﺑﻪ ﻣﺘﺪ get ﻣﺤﺪﻭﺩﻳﺖ ﻭﺟﻮﺩ ﺩﺍﺭﺩ.
- POST: ﺑﻪ ﻃﻮﺭ ﮐﻠﯽ ﺍﺯ ﺍﻳﻦ ﻭﻳﮋﮔﯽ ﺑﺮﺍﯼ ﺯﻣﺎﻧﯽ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﮐﻨﻴﻢ ﮐﻪ ﺍﻣﻨﻴﺖ ﺑﻴﺸﺘﺮﯼ ﻻﺯﻡ ﺩﺍﺭﻳﻢ؛ ﭼﺮﺍ ﮐﻪ ﺍﻳﻦ ﻣﺘﺪ، ﺩﺍﺩﻩ ﻫﺎ ﺭﺍ ﺩﺭ ﻣﺮﻭﺭﮔﺮ ﻧﺸﺎﻥ ﻧﻤﯽ ﺩﻫﺪ. ﻣﺜﻼ ﻓﺮﺽ ﮐﻨﻴﺪ ﻣﯽ ﺧﻮﺍﻫﻴﺪ ﻣﻘﺪﺍﺭﯼ ﺭﺍ ﺩﺭ ﭘﺎﻳﮕﺎﻩ ﺩﺍﺩﻩ ﻫﺎ ﺛﺒﺖ ﮐﻨﻴﺪ ﻭ ﻳﺎ ﻣﯽ ﺧﻮﺍﻫﻴﺪ ﺭﺍﻳﺎﻧﺎﻣﻪ ﺍﯼ ﺭﺍ ﺍﺭﺳﺎﻝ ﮐﻨﻴﺪ.
ﻧﮑﺘﻪ: ﺩﺭ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺍﻳﻦ ﻣﺘﺪ ﻫﻴﭻ ﻣﺤﺪﻭﺩﻳﺘﯽ ﺑﺮﺍﯼ ﺍﻧﺪﺍﺯﻩ ﺩﺍﺩﻩ ﺍﺭﺳﺎﻟﯽ ﻧﺪﺍﺭﻳﻢ.
ﺧﻮﺏ ﺯﻣﺎﻥ ﺁﻥ ﺭﺳﻴﺪﻩ ﮐﻪ ﻣﺎ ﺑﺎ ﻫﻢ ﻓﺮﻣﯽ ﺑﺴﺎﺯﻳﻢ ﻭ ﺍﺯ ﺩﺍﻧﺶ ﮐﺴﺐ ﺷﺪﻩ ﺗﺎ ﺑﻪ ﺣﺎﻝ ﺍﺳﺘﻔﺎﺩﻩ ﮐﻨﻴﻢ. ﺁﻣﺎﺩﻩ ﺍﻳﺪ؟
ﺍﺑﺘﺪﺍ ﻓﺎﻳﻠﯽ ﺑﺎ ﻧﺎﻡ form.php ﺳﺎﺧﺘﻪ ﻭ ﺩﺭ ﭘﻮﺷﻪ www/php ﮐﻪ ﻗﺒﻼ ﺩﺭ ﭘﻮﺷﻪ ﺑﺮﻧﺎﻣﻪ WampServer ﺳﺎﺧﺘﻪ ﺍﻳﺪ ﻗﺮﺍﺭ ﺩﻫﻴﺪ. ﺣﺎﻝ ﺑﺮﻧﺎﻣﻪ ﺭﺍ ﺍﺟﺮﺍ ﮐﺮﺩﻩ ﻭ ﺑﻪ ﺁﺩﺭﺱ http://127.0.0.1/php/form.php ﺑﺮﻭﻳﺪ ﻭ ﻳﺎ ﺍﺯ ﻃﺮﻳﻖ ﺁﻳﮑﻮﻥ ﺑﺮﻧﺎﻣﻪ، Localhost ﺭﺍ ﺍﻧﺘﺨﺎﺏ ﮐﻨﻴﺪ. ﻓﻌﻼ ﻳﮏ ﺑﺮﮔﻪ ﺳﻔﻴﺪ ﺑﻴﺶ ﻧﻴﺴﺖ ﺍﻣﺎ ﺩﺭ ﺍﺩﺍﻣﻪ ﺍﻳﻦ ﺑﺮﮔﻪ ﺭﺍ ﺑﺎ ﻓﺮﻡ ﺧﻮﺩ ﭘﺮ ﻣﯽ ﮐﻨﻴﻢ.
ﻧﮑﺘﻪ: ﻫﻤﺎﻧﻄﻮﺭ ﮐﻪ ﺩﺭ ﺑﺎﻻ ﮔﻔﺘﻴﻢ ﺑﺮﺍﯼ ﺍﻳﻦ ﻗﺴﻤﺖ ﻣﺎ ﺩﻭ ﻣﺮﺣﻠﻪ ﮐﺎﺭ ﺩﺍﺭﻳﻢ: ﺳﺎﺧﺖ ﻓﺮﻡ ﻭ ﻧﻮﺷﺘﻦ ﮐﺪ ﭘﯽ ﺍﭺ ﭘﯽ. ﻧﮑﺘﻪ ﻗﺎﺑﻞ ﺗﻮﺟﻪ ﺍﻳﻦ ﺍﺳﺖ ﮐﻪ ﻣﺎ ﻣﯽ ﺗﻮﺍﻧﻴﻢ ﺑﻪ ﺩﻭ ﺷﮑﻞ ﺍﻳﻦ ﮐﺎﺭ ﺭﺍ ﺍﻧﺠﺎﻡ ﺩﻫﻴﻢ. ﻳﮑﯽ ﮔﺬﺍﺷﺘﻦ ﻫﺮ ﺩﻭ ﻗﺴﻤﺖ ﻳﻌﻨﯽ ﻓﺮﻡ ﻭ ﮐﺪﻫﺎﯼ ﭘﯽ ﺍﭺ ﭘﯽ ﺩﺭ ﺩﺍﺧﻞ ﻳﮏ ﻓﺎﻳﻞ ﻭ ﺩﻳﮕﺮﯼ ﺟﺪﺍ ﮐﺮﺩﻥ ﺍﻳﻦ ﺩﻭ ﻗﺴﻤﺖ ﺑﻪ ﺻﻮﺭﺗﯽ ﮐﻪ ﻓﺮﻡ ﺩﺭ ﻳﮏ ﻓﺎﻳﻞ ﺑﺎﺷﺪ ﻭ ﮐﺪ ﭘﯽ ﺍﭺ ﭘﯽ ﺩﺭ ﻓﺎﻳﻞ ﺩﻳﮕﺮ. ﺍﺑﺘﺪﺍ ﻣﺎ ﺑﻪ ﺷﮑﻞ ﺩﻭ ﻓﺎﻳﻞ ﮐﻪ ﮐﺎﺭ ﺭﺍ ﺳﺎﺩﻩ ﺗﺮ ﻣﯽ ﮐﻨﺪ ﺍﻳﻦ ﮐﺎﺭ ﺭﺍ ﺍﻧﺠﺎﻡ ﻣﯽ ﺩﻫﻴﻢ ﻭ ﺩﺭ ﺁﻳﻨﺪﻩ ﺑﻪ ﺷﮑﻞ ﺗﮏ ﻓﺎﻳﻞ.
ﺩﺭ ﻓﺎﻳﻞ ﻓﺮﻡ ﺧﻮﺩ ﮐﺪﻫﺎﯼ ﺯﻳﺮ ﺭﺍ ﻭﺍﺭﺩ ﮐﻨﻴﺪ:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ﺁﻣﻮﺯﺵ ﺳﺎﺧﺖ ﻓﺮﻡ ﺍﭺ ﺗﯽ ﺍﻡ ﺍﻝ</title> <link rel="stylesheet" type="text/css" media="all" href="style.css" /> </head> <body> <!-- ﮐﺪ ﺑﺮﺍﯼ ﺳﺎﺧﺖ ﻓﺮﻡ - form.html --> <form action="form_handler.php" method="get"> <fieldset> <legend align="right">ﻟﻄﻔﺎ ﻓﺮﻡ ﺯﻳﺮ ﺭﺍ ﭘﺮ ﮐﻨﻴﺪ</legend> <label> ﻧﺎﻡ</label> <input type="text" name="name" /> <label> ﺭﺍﻳﺎﻧﺎﻣﻪ </label> <input type="text" name="email" /> <label>ﺩﻳﺪﮔﺎﻩ</label> <textarea name="comments" ></textarea> </fieldset> <input type="submit" name="submit" value="ﺍﺭﺳﺎﻝ" class="submit"/> </form> </body> </html> |
ﺣﺎﻝ ﻓﺮﻡ ﺧﻮﺩ ﺭﺍ ﺩﺭ ﻣﺮﻭﺭﮔﺮ ﻧﻈﺎﺭﻩ ﮐﻨﻴﺪ.
ﻗﺴﻤﺖ ﺑﻌﺪﯼ ﻓﺎﻳﻠﯽ ﺍﺳﺖ ﮐﻪ ﮐﺪﻫﺎﯼ ﭘﯽ ﺍﭺ ﭘﯽ ﺩﺭ ﺁﻥ ﻗﺮﺍﺭ ﺩﺍﺭﺩ. ﻓﺎﻳﻞ ﺩﻳﮕﺮﯼ ﺑﺎ ﻧﺎﻡ form_handler.php ﺑﺴﺎﺯﻳﺪ. ﺍﻳﻦ ﻓﺎﻳﻞ ﮐﺎﺭ ﺩﺭﻳﺎﻓﺖ ﻭ ﺳﺎﺯﻣﺎﻧﺪﻫﯽ ﺩﺍﺩﻩ ﻫﺎ ﺭﺍ ﺍﻧﺠﺎﻡ ﻣﯽ ﺩﻫﺪ. ﺍﻃﻼﻋﺎﺕ ﺯﻳﺮ ﺭﺍ ﺩﺭ ﺩﺍﺧﻞ ﺁﻥ ﺑﻨﻮﻳﺴﻴﺪ:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> ﭘﺎﺳﺦ </title> <link rel="stylesheet" type="text/css" media="all" href="style.css" /> </head> <body> <div id="contain"> <?php // ﭼﺎﭖ ﺩﺍﺩﻩ ﻫﺎﯼ ﺍﺭﺳﺎﻟﯽ $name = $_GET['name']; $email = $_GET['email']; $comments = $_REQUEST['comments']; echo 'ﺑﺎ ﺳﭙﺎﺱ <br /><span> ' . $name . '</span><br />ﺑﺮﺍﯼ ﺍﻳﻦ ﻧﻮﺷﺘﻪ <br />' ; ?> <div class="comment"> <?php echo $comments ; ?> </div><br /> ﻣﺎ ﺑﺎ ﺷﻤﺎ ﺗﻤﺎﺱ ﻣﯽ ﮔﻴﺮﻳﻢ ﺗﻮﺳﻂ ﺍﻳﻦ ﺭﺍﻳﺎﻧﺎﻣﻪ <br /> <div class="email"> <?php echo $email . '<br /><br />' ;?> </div> <a href="form.php">ﺑﺮﮔﺸﺖ</a> </div> </body> </html> |
ﻗﺒﻞ ﺍﺯ ﺍﻣﺘﺤﺎﻥ ﮐﺪﻫﺎ ﻳﮏ ﮐﺎﺭ ﺩﻳﮕﺮ ﻫﻢ ﺑﺎﻳﺪ ﺍﻧﺠﺎﻡ ﺩﻫﻴﻢ ﺗﺎ ﺩﺍﺩﻩ ﻫﺎ ﻫﻤﺎﻥ ﻃﻮﺭ ﮐﻪ ﻣﺎ ﻣﯽ ﺧﻮﺍﻫﻴﻢ ﻧﻤﺎﻳﺶ ﺩﺍﺩﻩ ﺷﻮﻧﺪ. ﻓﺎﻳﻞ ﺩﻳﮕﺮﯼ ﺑﺴﺎﺯﻳﺪ ﻭ ﻧﺎﻡ ﺁﻥ ﺭﺍ style.css ﺑﮕﺬﺍﺭﻳﺪ ﻭ ﮐﺪﻫﺎﯼ ﺯﻳﺮ ﺭﺍ ﺩﺭ ﺩﺍﺧﻠﺶ ﺑﻨﻮﻳﺴﻴﺪ.
body { background-color:#fff; text-align: center; color:#333;} /* ﻗﺴﻤﺖ ﻓﺮﻡ */ form { width:700px; margin:100px auto auto;} fieldset{border:1px solid #ddd;} label, input, textarea{margin:5px 10px 0px auto; text-align: right; clear: both; float:right;width:60%;} input{margin:5px 10px 10px auto} textarea{width:80%; height:150px;} .submit{float: none; text-align: center; border:1px solid #ddd; color:#039;} /* ﻗﺴﻤﺖ ﭘﯽ ﺍﭺ ﭘﯽ */ |
ﺩﺭ ﺣﺎﻝ ﺣﺎﺿﺮ ﻣﺎ ﺳﻪ ﻓﺎﻳﻞ ﺩﺍﺭﻳﻢ؛ ﻳﮑﯽ ﺑﺮﺍﯼ ﺳﺎﺧﺘﻦ ﻓﺮﻡ٬ ﺩﻳﮕﺮﯼ ﺑﺮﺍﯼ ﮐﺎﺭ ﺑﺎ ﺩﺍﺩﻩ ﻫﺎﯼ ﻓﺮﻡ ﻭ ﺁﺧﺮﯼ ﺑﺮﺍﯼ ﺳﺎﺧﺘﺎﺭ ﻧﻤﺎﻳﺶ ﺩﺍﺩﻩ ﻫﺎ ﺩﺭ ﻣﺮﻭﺭﮔﺮ. ﺣﺎﻝ ﻣﯽ ﺗﻮﺍﻧﻴﺪ ﻋﻤﻠﮑﺮﺩ ﮐﺪ ﺧﻮﺩ ﺭﺍ ﺑﺒﻴﻨﻴﺪ.
ﻧﮑﺘﻪ ۱: ﻫﺮ ﺳﻪ ﺍﻳﻦ ﻓﺎﻳﻞ ﻫﺎ ﺑﺎﻳﺪ ﺩﺭ ﺩﺍﺧﻞ ﻳﮏ ﭘﻮﺷﻪ ﻗﺮﺍﺭ ﮔﻴﺮﻧﺪ.
ﻧﮑﺘﻪ ۲: ﻣﺎ ﺍﺯ ﻣﺘﺪ GET ﻭ REQUEST ﺑﺮﺍﯼ ﺍﺭﺳﺎﻝ ﺩﺍﺩﻩ ﻫﺎ ﺍﺳﺘﻔﺎﺩﻩ ﮐﺮﺩﻳﻢ٬ ﻟﻄﻔﺎ ﻧﮕﺎﻫﯽ ﻫﻢ ﺑﻪ ﻧﺸﺎﻧﯽ ﻣﺮﻭﺭﮔﺮ ﺑﻌﺪ ﺍﺯ ﻓﺸﺮﺩﻥ ﺩﮐﻤﻪ ﺍﺭﺳﺎﻝ ﺑﻴﺎﻧﺪﺍﺯﻳﺪ. ﭼﻪ ﻣﯽ ﺑﻴﻨﻴﺪ؟ ﺑﻠﻪ ﺩﺍﺩﻩ ﻫﺎ ﺑﻪ ﺻﻮﺭﺕ ﻧﺎﻡ ﻭ ﻣﻘﺪﺍﺭ ﺩﺭ ﺩﺍﺧﻞ ﻧﺸﺎﻧﯽ ﻣﺮﻭﺭﮔﺮ ﺩﻳﺪﻩ ﻣﯽ ﺷﻮﻧﺪ. ﺣﺎﻝ ﺩﺭ ﺩﻭ ﻓﺎﻳﻞ ﻓﺮﻡ ﻭ ﭘﯽ ﺍﭺ ﭘﯽ ﻫﺮ ﺟﺎ ﮐﻪ GET ﻳﺎ REQUEST ﻣﯽ ﺑﻴﻨﻴﺪ، ﺁﻧﻬﺎ ﺭﺍ ﺑﺎ POST ﻋﻮﺽ ﮐﻨﻴﺪ. ﺣﺎﻝ ﭼﻪ ﺷﺪ؟ ﺍﺛﺮﯼ ﺍﺯ ﺩﺍﺩﻩ ﻫﺎ ﺩﺭ ﻣﺮﻭﺭﮔﺮ ﻧﻴﺴﺖ. ﺑﻌﺪ ﺍﺯ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ POST ﺩﻳﮕﺮ ﺩﺍﺩﻩ ﻫﺎ ﺩﺭ ﻣﺮﻭﺭﮔﺮ ﻓﺮﺳﺘﺎﺩﻩ ﻧﻤﯽ ﺷﻮﻧﺪ.
ﻧﮑﺘﻪ ۳: ﺍﮔﺮ ﺩﺭ ﻓﺎﻳﻞ form_handler.php ﺩﻗﺖ ﮐﻨﻴﺪ ﻣﺎ ﺍﺯ ﻣﺘﻐﻴﺮﯼ ﺑﺎ ﻧﺎﻡ $_REQUEST ﺑﻪ ﺻﻮﺭﺕ ﺁﻧﭽﻪ ﺩﺭ ﺯﻳﺮ ﻣﯽ ﺑﻴﻨﻴﺪ ﺍﺳﺘﻔﺎﺩﻩ ﮐﺮﺩﻳﻢ.
$comments = $_REQUEST['comments']; |
ﺑﻪ ﺍﻳﻦ ﻧﻮﻉ ﻣﺘﻐﻴﺮ ﻓﺮﺍ ﺟﻬﺎﻧﯽ ﻣﯽ ﮔﻮﻳﻨﺪ ﮐﻪ ﺍﻃﻼﻋﺎﺕ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺍﺯ ﻓﺮﻡ ﺭﺍ ﺫﺧﻴﺮﻩ ﻣﯽ ﮐﻨﺪ. ﺩﺭ ﺁﻳﻨﺪﻩ ﺩﺭ ﻣﻮﺭﺩ ﺍﻳﻦ ﻧﻮﻉ ﻣﺘﻐﻴﺮ ﺑﻴﺸﺘﺮ ﺣﺮﻑ ﻣﯽ ﺯﻧﻴﻢ.
ﻧﮑﺘﻪ ۴: ﮐﺪﻫﺎﯼ ﺩﺍﺩﻩ ﺷﺪﻩ ﺩﺭ ﺍﻳﻦ ﺩﺭﺱ ﻗﺒﻼ ﺍﻣﺘﺤﺎﻥ ﺷﺪﻩ ﺍﺳﺖ٬ ﭘﺲ ﺍﮔﺮ ﺍﺣﻴﺎﻧﺎ ﺑﻪ ﺧﻄﺎﻳﯽ ﺑﺮﺧﻮﺭﺩ ﮐﺮﺩﻳﺪ، ﻣﻤﮑﻦ ﺍﺳﺖ ﮐﻪ ﺷﻤﺎ ﮐﺪﻫﺎ ﺭﺍ ﺍﺷﺘﺒﺎﻩ ﻭﺍﺭﺩ ﮐﺮﺩﻩ ﺑﺎﺷﻴﺪ. ﺍﻣﺎ ﺍﮔﺮ ﺍﺯ ﮐﺎﺭ ﺧﻮﺩ ﻣﻄﻤﺌﻦ ﻫﺴﺘﻴﺪ ﻟﻄﻔﺎ ﻣﻮﺭﺩ ﺧﻄﺎ ﺭﺍ ﺩﺭ بخش نظرات ﺍﻳﻦ ﺩﻭﺭﻩ ﺍﻃﻼﻉ ﺩﻫﻴﺪ ﺗﺎ ﻣﺸﮑﻞ ﺭﺍ ﺣﻞ ﮐﻨﻴﻢ.
ﺑﺮﺍﯼ ﻳﺎﻓﺘﻦ ﺧﻄﺎﯼ ﺍﺣﺘﻤﺎﻟﯽ ﻓﻘﻂ ﮐﺎﻓﻴﺴﺖ ﮐﻪ ﺑﻪ ﺧﻂ ﺍﺷﺎﺭﻩ ﺷﺪﻩ ﺩﺭ ﺧﻄﺎ ﺭﺟﻮﻉ ﮐﻨﻴﺪ ﻭ ﺑﻌﺪ ﺩﺭ ﺑﺮﮔﻪ ﻣﻮﺭﺩ ﻧﻈﺮ، ﺧﻂ ﺧﻄﺎﺩﺍﺭ ﺭﺍ ﭘﻴﺪﺍ ﮐﺮﺩﻩ ﻭ ﺑﺎ ﮐﺪ ﻧﻮﺷﺘﻪ ﺷﺪﻩ ﻣﻨﻄﺒﻖ ﮐﻨﻴﺪ.
ﻧﮑﺘﻪ ۵: ﺍﮔﺮ ﺑﻪ ﺟﺎﯼ ﻧﻮﺷﺘﻪ ﻫﺎﻳﯽ ﻣﺜﻞ ﻧﺎﻡ ﻭ... ﻣﻄﻠﺒﯽ ﻧﺒﻮﺩ، ﺍﻳﻦ ﻳﻌﻨﯽ ﮐﻪ ﻣﺘﻐﻴﺮ ﺧﺎﻟﯽ ﺍﺳﺖ ﻭ ﻣﺸﮑﻠﯽ ﺩﺭ ﺍﻧﺘﻘﺎﻝ ﺩﺍﺩﻩ ﺑﻪ ﻣﺘﻐﻴﺮ ﺍﺗﻔﺎﻕ ﺍﻓﺘﺎﺩﻩ ﺍﺳﺖ.
ﺧﻮﺏ ﺍﻳﻦ ﺩﺭﺱ ﻫﻢ ﺑﻪ ﭘﺎﻳﺎﻥ ﺭﺳﻴﺪ. ﺍﻣﻴﺪﻭﺍﺭﻡ ﮐﻪ ﺑﺎ ﺗﻤﺮﻳﻦ ﺑﺘﻮﺍﻧﻴﺪ ﭼﻨﻴﻦ ﮐﺎﺭﯼ ﺭﺍ ﺩﺭ ﻧﻤﻮﻧﻪ ﻫﺎﯼ ﺩﻳﮕﺮ ﺍﻧﺠﺎﻡ ﺩﻫﻴﺪ. ﺩﺭ ﺩﺭﺱ ﺑﻌﺪﯼ ﺑﻪ ﺷﺮﻁ ﻫﺎ ﺩﺭ ﭘﯽ ﺍﭺ ﭘﯽ ﻣﯽ ﭘﺮﺩﺍﺯﻳﻢ ﮐﻪ ﺑﻪ ﻣﺎ ﮐﻤﮏ ﻣﯽ ﮐﻨﻨﺪ ﻗﺒﻞ ﺍﺯ ﭼﺎﭖ ﻫﺮ ﺩﺍﺩﻩ ﮔﺮﻓﺘﻪ ﺷﺪﻩ ﺍﺯ ﻓﺮﻡ، ﺁﻥ ﺭﺍ ﻣﻮﺭﺩ ﺍﺭﺯﻳﺎﺑﯽ ﻗﺮﺍﺭ ﺩﻫﻴﻢ.
ﺗﺎ ﺑﻌﺪ...
مطالب مرتبط
![Share](/sites/all/modules/addtoany/images/share_save_171_16.png)