Custom form input field missing from &$values when hooking into tokenValues
Most likely you are not adding order_id when the form is being posted back to the server

the quickform package basically filters out all variables that have not been added to the form. The buildForm hook is called even when the form is posted, so you might want to ensure that order_id is also added there. In most cases this happens automatically, however if we are using ajax for build parts of the form, it gets a bit trickier

$_GET['pid'] is available only during the first GET request. The POST request sends a very minimal set of GET variables. Try using this variation:`

function invoicetoken_civicrm_buildForm($formName, &amp;$form) {
  //add order_id to our form
  if($formName == 'CRM_Contact_Form_Task_Email') {
    $order_id = CRM_Utils_Request::retrieve('order_id', 'String', $form);
    $form-&gt;addElement('hidden','order_id', $order_id);
  }
}`