You are here

function contribute_form_submit in Contribute 6

File

./contribute.module, line 59
Lets users contribute to projects

Code

function contribute_form_submit($form, &$form_state) {
  global $user;

  // Load the node the form was submitted from
  // Note: this only works when the node is submitted from /node/#
  // and will need to be fixed at some point to be more robust
  $nid = $form['#action'];
  $nid = $form['#parameters'][2]->nid;
  $node = node_load($nid);
  drupal_set_message("nid is {$nid}");
  dpm($form);
  $amount = $form_state['values']['transfer']['amount'];
  $balance = contribute_get_user_balance($user->uid);
  if ($amount > $balance) {
    drupal_set_message("Sorry, not enough funds");
    return;
  }
  $needed = contribute_get_node_balance($nid);
  drupal_set_message("needed = {$needed} , amount = {$amount}");
  $amount = $amount > $needed ? $needed : $amount;
  contribute_contribution($user->uid, $nid, $amount);
}