Link to home
Create AccountLog in
Avatar of Modifier1000
Modifier1000Flag for United States of America

asked on

Simple PHP addition using Drupal 7 Forms API

Hello Experts,

I want $form['prior_current_total'] ['total_1'] to be the sum of prior_1 and current_1

   function footballTotal_admin_settings_form($node, &$form_state)
     $form = array();
     $form['overview'] = array 
						  '#markup' => t('This interface allows administrators to manage general footballTotal settings.'),
						  '#prefix' => '<p>',
						  '#suffix' => '</p>',
     $form['prior_current_total'] = array 
						  '#title' => t('Prior / Current / Total Calculations'),
						  '#description' => t('Fieldset for all Prior, Current, and Total values.'),
						  '#type' => 'fieldset',
						  '#collapsible' => TRUE,
						  '#collasped' => FALSE,
     $form['prior_current_total'] ['prior_1'] = array 
						  '#title' => t('Prior'),
						  '#description' => t('Enter the Prior money value per row.'),
						  '#type' => 'textfield',
						  '#default_value' => '$2.00',
      $form['prior_current_total'] ['current_1'] = array 
						  '#title' => t('Current'),
						  '#description' => t('Enter the Current money value per row.'),
						  '#type' => 'textfield',
						  '#default_value' => '$3.00',
	  $totals_1 = $form['prior_1'].value + $form['current_1'].value;
      $form['prior_current_total'] ['total_1'] = array 
						  '#title' => t('Total'),
						  '#description' => t('Enter the Total money value per row.'),
						  '#type' => 'textfield',
						  '#default_value' => $totals_1,
      $form['submit'] = array
						  '#type' => 'submit',
						  '#value' => t('Save'),
     return $form;

Open in new window

Not only do I need them to sum, but to do it on-the-fly...any ideas?
Avatar of stephencolson
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Modifier1000


Thank you!