Let me explain the idea behind our, WordPress and PHP "API" (althout PHP is a framework, not an API 🙂 ).
CRED API is a set of hooks and filter, this means, there are a few functions that do things on certain moments of a CRED Form's "life".
As example the cred hook cred_save_data hooks into the moment when the post is saved to the database (right after).
The hook itself does nothing.
It just makes sure, that the code wich you put INTO that hook, is executed at the correct moment.
Now, all code that is IN the hook is what you need to build using PHP and the WordPress API.
The WordPress API will provide you with the correct functions, such as "update_post_meta", wich puts the correct information into a Custom Field in the Database.
The CRED API makes sure that the WordPress function gets executed at the correct moment.
And PHP will help you make the calculations, using the arithemtic oerators it offers (and much more)
Let's see the below very simple example, it updates a post meta, inside a CRED cred_save_data function, and uses the PHP operator "+" to sum a value to another value, before it updates the post meta.
//this adds the action at the right moment when we save stuff to the database with a CRED form
add_action('cred_save_data', 'my_save_data_action',10,2);
//This is the function that is executed, when above action is added. It acts on a specific CRED form only
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==12)
{
$value_one = 10; //either numerical values, or some value from a $_POST field, or some value from a get_post_meta field
$value_two = 2; //same as above, you may add as many $variables as you need
//now let's sum up the above two values
$the_sum = $value_one + $value_two;
//now let's update a Post Field with the above new value
update_post_meta($post_id, 'wpcf-your-field-slug', $the_sum);
}
}
The above code is built of the CRED API hook, that will make sure all code INSIDE The hook gets executed on form save to database, and only on this one form.
All code INSIDE The hook, is built with WordPress and PHP.
The field for your total sum, can be added to the currently edited or created post, or if it's on another post type, you have to specify the $post_id in your code above.
It depends on where you want the field to be appearing and used.
If you browse my pastebin you will see several example CRED functions, all built with above process:
http://pastebin.com/u/bedas