edgar.dueñas
Enviado por edgar.dueñas el Mié, 11/05/2016 - 15:05

Una forma de alterar el submit es usando hook_form_alter y luego usando un callback como funcion y asignarselo al submit

($form['actions']['submit']['#submit'][]).

Para procesar un formulario es necesario identificarlo por el id y cuando es un formulario del tipo de contenido el id se forma asi: nombre_tipo_contenido_node_form.

<?php
function transaction_money_form_alter(&$form, &$form_state, $form_id) {
 
  global $user;
 
  if ($form_id === 'contributing_donors_node_form') {
        $form['field_user_approver']['und'][0]['uid']['#default_value'] = $user->uid;
        $form['actions']['submit']['#submit'][]='contributing_donor_callback';
        //$form['field_user_approver']['und'][0]['#default_value'] = array($user->uid => $user->name);
  }    
 
  if(strstr($form_id, 'webform_client_form_40')) { 
 
        $form['#submit'][] = 'return false;';
        // add the ajax properties to the submit button
        $form['actions']['submit']['#ajax'] = array(
        'callback' => 'suscribete_js_submit',
        'wrapper' => 'webform-client-form-40',
        'method' => 'replace',
        'effect' => 'fade',
    );
  }
}
 
function contributing_donor_callback($form,$form_state){
     //my code here!!
     //execute after the user submit the node form
     //and then redirect user to another place,after executing the code above field_donations['und'][0]
    if($form['field_donations']['und']['#value'] == 35 || $form['field_donations']['und']['#value'] == 34) {
        //dpm($form['field_user_donation']['und']['#value']);
        //dpm($form['field_amount_contributing']['und'][0]['value']['#value']);
        $account = user_load($form['field_user_donation']['und']['#value']);
        array_push($account->field_total_donations['und'], array("value" => $form['field_amount_contributing']['und'][0]['value']['#value']));
        $edit = array(
        'field_total_donations' => array(
            'und' => $account->field_total_donations['und']
            ),
        );
        user_save($account, $edit);
    }
 
}
?>