I've searched on SE and google for 2 weeks, and mostly found JavaScript or jquery solutions. I have very little knowledge of coding either. I have altered a custom Drupal module form and added a user "wager" input. I have #element
validate (it is a positive integer) working correctly for each row of the "wager" input. It is also saving correctly to MySQL table for each "wager" input.
Questions: How do I sum all of the users "wager" boxes and compare >=
to the users total available points for form validate? Is there an alternative solution to the jquery or JS? If not, how the heck would I begin to implement for that form? I can post code or screenshots if needed.
Edit: added screenshot of form:
> // * Menu callback; presents the list of all weeks and games. *
> function mypicks_all_page($league) { return theme('mypicks_all',
> array('league' => $league)); }
>
>
> /** * Display the list of all weeks and games. * The user would pick
> a week link from here to make their weekly picks. */ function
> theme_mypicks_all($variables) { global $_PICKEM_MY_LEAGUES; global
> $user; /*******************blakestart*/
>
> /********blakeend*******************/ $league =
> $variables['league'];
>
> // Param check: user must be a member of this league to continue.
> if ( !is_my_league($league) ) {
> return drupal_not_found(); }
>
> drupal_set_title(t('My Picks - %user_name', array('%user_name' =>
> $user->name)), PASS_THROUGH);
>
> $breadcrumb = drupal_get_breadcrumb(); $breadcrumb[] =
> l($league->name, 'pickem/' . $league->lid);
> drupal_set_breadcrumb($breadcrumb);
>
> $teams = get_teams(array('gameset_id' => $league->gsid)); $games =
> get_games(array('league_id' => $league->lid), array('by_week' => 1,
> 'order_by' => 'week_ended, g.gamestart, g.gid'));
>
>
> $header = array(t('Week'), t('Games')); $rows = array(); foreach
> ($games as $wid => $weeks_games) {
> $cols = array();
> $current_week = '';
> foreach ($weeks_games as $gid => $game) {
>
>
>
>
>
> // Figure out the matchup operator.
> if ($game->neutral_venue == 1) {
> $matchup = "vs ";
> }
> else {
> $matchup = "@";
> }
>
> // The first column should be the week number link.
> if ( count($cols) == 0 ) {
> $cols[] = array('data' => l(t('Week %wk_number', array
('%wk_number' => $game->wk_number)),
> "pickem/$league->lid/mypicks/" . $wid, array('html' => TRUE)), 'class'
> => 'week');
> }
> $current_week .= '<div class="picks-float">' . $teams[$game->v_id]->short_name . '<br/>' . $matchup .
> $teams[$game->h_id]->short_name . '</div>';
> }
> $cols[] = $current_week;
> $rows[] = $cols; } return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' =>
> array('pickem-mypicks-all')))); }
>
>
> function mypicks_week_form($form, &$form_state, $league, $week) {
> global $user; global $wager;
>
>
>
> $form = build_picks_week_form($form, $form_state, $league, $week,
> $user, $wager); return $form; }
>
>
> function theme_mypicks_week_form($variables) { global $user;
>
>
> $form = $variables['form']; $league =
> league_load($form['league_id']['#value']);
>
> // Drupal sets the default timezone to be the user's //if
> available, otherwise, the system's. $timezone =
> date_default_timezone_get();
>
> $header = array(); $header[] = t('Matchup'); if
> ($league->scoring_engine->features['with_confidence'] == 1) {
> $header[] = array('data' => t('Confidence'), 'class' => 'confidence-pts'); } $header[] = t('Status'); $header[] =
> array('data'=>t('Game time'), 'title'=> t('Timezone is @timezone',
> array('@timezone' => $timezone))); if
> ($league->scoring_engine->features['with_spread'] == 1){ $header[] =
> array('data'=>t('Wager'), 'title'=>'This is Wager column'); } $rows
> = array(); $last = count(element_children($form['games'])); $count = 0; foreach (element_children($form['games']) as $gid) {
> $count++;
> $cols = array();
>
> if (isset($form['games'][$gid]['pick'])) {
> if ($form['games'][$gid]['pick']['#default_value'] == '') {
> $cols[] = array('data' => drupal_render($form['games'][$gid]['pick']), 'class' => 'no-pick');
> }
> else {
> $cols[] = array('data' => drupal_render($form['games'][$gid]['pick']));
> }
> }
> else {
> $cols[] = drupal_render($form['games'][$gid]['pick_v_score']) . drupal_render($form['games'][$gid]['pick_h_score']);
> }
>
> // Render confidence boxen
> if ($league->scoring_engine->features['with_confidence'] == 1) {
> if($form['games'][$gid]['confidence']['#default_value'] == '') {
> $cols[] = array('data' => drupal_render($form['games'][$gid]['confidence']),
> 'class'=>'no-pick');
> } else {
> $cols[] = array('data' => drupal_render($form['games'][$gid]['confidence']));
> }
> }
>
> $cols[] = drupal_render($form['games'][$gid]['pick_status']);
>
> $cols[] = drupal_render($form['games'][$gid]['gamestart']);
>
>
> $cols[] = drupal_render($form['games'][$gid]['wager']);
>
>
>
> $rows[] = $cols; }
>
> $output = $league->scoring_engine->description; $output .= '<p>' .
> t('Game time is represented in the @timezone timezone.',
> array('@timezone' => $timezone)) . '</p>'; $output .= theme('table',
> array('header' => $header, 'rows' => $rows, 'attributes' =>
> array('class' => array('pickem-mypicks-week')))); $output .=
> drupal_render_children($form); return $output; }
>
>
>
>
>
>
>
> function mypicks_week_form_validate($form, &$form_state) { $league =
> league_load($form_state['values']['league_id']); if
> (($league->scoring_engine->features['with_confidence'] == 1)) {
> $conf_values = array();
> $max_conf = count($form_state['values']['games']);
> foreach ($form_state['values']['games'] as $gid => $pick) {
>
> // Skip empty confidence values.
> if ($pick['confidence'] == '') {
> continue;
> }
>
> // Out of range confidence numbers
> if (!is_numeric($pick['confidence']) || $pick['confidence'] < 1 || $pick['confidence'] > $max_conf) {
> form_set_error('games][' . $gid . '][confidence', t('Confidence point must be a number from 1 to %max.', array('%max' =>
> $max_conf)));
> }
>
> // Duplicate confidence numbers
> if (isset($conf_values[$pick['confidence']])) {
> form_set_error('games][' . $gid . '][confidence', t('Confidence point %pt already used.', array('%pt' =>
> $pick['confidence'])));
> }
> $conf_values[$pick['confidence']] = TRUE;
>
>
>
>
>
>
> }}} /** * Implements hook_form_alter(). */ function webform_calc_form_alter(&$form, $form_state, $form_id) { if
> ($form_id == 'mypicks-week-form') {
> $form['#validate'][] = 'webform_calc_validate'; } } function webform_calc_validate($form, &$form_state) {
> switch($form_state['input']['details']['page_num']) {
> case '1':
> $bet = $form_state['input']['submitted']['wager'];
>
>
> $totalbet = $wager + $wager;
> form_set_value(
> $form['submitted']['totalbet'], $totalbet, $form_state);
> break;
> case '2':
> $totalbet = $form_state['storage']['submitted'][4];
> $form_state['webform']['component_tree']['children']
> [11]['value'] = 'Total bet: ' . $totalbet;
> break; } return $form; }
>
> function mypicks_week_form_submit($form, &$form_state) { global
> $user;
>
>
> $league = league_load($form_state['values']['league_id']); $week =
> week_load($form_state['values']['week_id']);
> $form_state['values']['wager'] = array();
>
>
>
> // You should not be able to save picks after lockup. if
> ($league->pick_lock == PICKEM_PICK_LOCK_WEEK && $week->week_started ==
> 1) {
> drupal_set_title(t('%week_name picks are locked.', array('%week_name' => $week- >wk_name)), PASS_THROUGH);
> return t("You cannot change your picks now."); }
>
>
>
>
>
>
>
> // Check and see if the user wants to save to all their leagues that
> use the same gameset. $save_for_these_leagues = array(); if (
> $form_state['values']['apply_to_all_leagues'] == 1 ) {
> $save_for_these_leagues = get_my_leagues($league->gsid); } else {
> $save_for_these_leagues[] = $league; }
>
> foreach ($save_for_these_leagues as $l) {
> // Only save for league using the same scoring system.
> $success = TRUE;
> if ($l->scoring_type == $league->scoring_type) {
> foreach ($form_state['values']['games'] as $gid => $pick) {
> $pick['gid'] = $gid;
> if (set_pick($user->uid, $l, $pick, 'user') != TRUE) {
> $success = FALSE;
> }
> }
>
>
>
> if ($success) {
>
>
>
>
> drupal_set_message(t('The picks have been saved for league <i>%league</i>.', array('%league' => $l->name)));
>
> }
> } } } //