'Opencart 2.1.0.2 insert data in database

I created a function in catalog->model->total->coupon.php which adds a coupon in the database. What i want is for it to run when the user press the subscribe button to a pop-up that i created. What should i do. I tried inserting a script in coupon.php but the site crashed. Where should i put the script that makes the function run only when the button of the pop-up is clicked. Below is the function that inserts the data in the database

public function coupon_test() { 
               $this->db->query("INSERT INTO `" . DB_PREFIX . "coupon` SET name = 'New coupon', code = 'COUPON2', type = 'P', discount = '50', logged = '0', shipping = '0', total = '0', date_start = CURRENT_DATE(), date_end = DATE_ADD(CURRENT_DATE(), INTERVAL 6 DAY), uses_customer = '1', status = '1', date_added = NOW()");   
            }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source