I am able to modify the $user->profile_fields but am not able to modify other variables with all the code in Display Format.

I lost my forms functionality when I put all the code in Computed Code.

My first set up is:
Computed Code:

 function donate_form($form_state){
    
  $form['transfer'] = array(
    '#type' => 'fieldset',
    '#title' => t('Donate to project'),
    '#tree' => TRUE,
  );
  $form['transfer']['amount'] = array(
    '#type' => 'textfield',
    '#title' => t('Amount'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter the amount to donate to project'),
  );
  $form['submit'] = array('#type' => 'submit', '#value' => t('Load'));
return $form;
  }
  
function donate_form_submit($form, &$form_state) {
    global $user;
    profile_load_profile($user);
    $amount_to_donate = $form_state['values']['transfer']['amount'];
    print "Balance before: $user->profile_balance; <br/>";
    $edit = array(
     'profile_balance' => $user->profile_balance - $amount_to_donate,
    );
    profile_save_profile($edit,$user,"Account Information");
    $node->field_donated[0]['value'] += $amount_to_donate;
    node_save($node);
    dpm($node);
    
  }

  function donate_form_validate($form, &$form_state) {
   global $user;
   profile_load_profile($user);
   $amount_to_transfer = $form_state['values']['transfer']['amount'];
  if ($amount_to_transfer > $user->profile_balance ) {
    form_set_error('', t('You don\'t have enough money!'));
  }
}

$node_field[0]['value'] = drupal_get_form('donate_form');

Display Format:
$display = $node_field_item['value'];

In this configuration, the submit button does not seem to work, though the form displays as expected.

The other configuration

Computed Code:
$node_field[0]['value'] = '';

Display Format:

 function donate_form($form_state){
    
  $form['transfer'] = array(
    '#type' => 'fieldset',
    '#title' => t('Donate to project'),
    '#tree' => TRUE,
  );
  $form['transfer']['amount'] = array(
    '#type' => 'textfield',
    '#title' => t('Amount'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter the amount to donate to project'),
  );
  $form['submit'] = array('#type' => 'submit', '#value' => t('Load'));
return $form;
  }
  
function donate_form_submit($form, &$form_state) {
    global $user;
    profile_load_profile($user);
    $amount_to_donate = $form_state['values']['transfer']['amount'];
    print "Balance before: $user->profile_balance; <br/>";
    $edit = array(
     'profile_balance' => $user->profile_balance - $amount_to_donate,
    );
    profile_save_profile($edit,$user,"Account Information");
    $node->field_donated[0]['value'] += $amount_to_donate;
    node_save($node);
    dpm($node);
    
  }

  function donate_form_validate($form, &$form_state) {
   global $user;
   profile_load_profile($user);
   $amount_to_transfer = $form_state['values']['transfer']['amount'];
  if ($amount_to_transfer > $user->profile_balance ) {
    form_set_error('', t('You don\'t have enough money!'));
  }
}

$display = drupal_get_form('donate_form');

In this configuration I cannot edit $field_donated (or $node->field_donated[0]['value'];)

Comments

mmjvb’s picture

Status: Active » Closed (outdated)