setcookie doesn't work in submit function nor tpl.php
Thank you everyone, I got the answer. 
It seems Drupal supports session instead of cookie.(Sorry I cannot find the reference again.) Therefore, I used session to implement my function. 

Here are some reference:

Example for session:
https://www.drupal.org/node/360542

How to set session expiration:
https://www.drupalgardens.com/documentation/cookie/expire