Title: Adding Values, Return 0
Last modified: September 1, 2016

---

# Adding Values, Return 0

 *  [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * (@fabbstar)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/adding-values-return-0/)
 * Hi Michael,
 * I hope you are well?
 * Hopefully a quick one…
 * I’m using the below shortcode to add up the values in a column and display the
   result in monetary terms e.g. £10.00
 * [cfdb-value tfilter=”Customer=$user_login&&Status=Completed” trans=”Value=parse_form_money(
   Value)&&SumField(Value)&&Value=number_format(Value,2)&&Value=concat(£,Value)”
   form=”FORM NAME” show=”Value”]
 * If there are no values to count I’d like it to return £0, instead of what it 
   currently does which is output nothing at all. Any ideas how I can do this?
 * Thanks,
    S
 * [https://wordpress.org/plugins/contact-form-7-to-database-extension/](https://wordpress.org/plugins/contact-form-7-to-database-extension/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/adding-values-return-0/#post-7719817)
 * I can’t think of a quick way. I think you have to add a [custom transform function](http://cfdbplugin.com/?page_id=1076)
   like this:
 *     ```
       require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBPermittedFunctions.php');
       function zero_if_null($x) {
           return is_null($x) ? 0 : $x;
       }
       cfdb_register_function('zero_if_null');
       ```
   
 * so you can add in the “trans”:
    `Value=zero_if_null(Value)`
 *  Thread Starter [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * (@fabbstar)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/adding-values-return-0/#post-7719821)
 * Hi Michael,
 * Thanks so much for the reply.
 * I can see how that should work, so I created the function using your shortcodes,
   actions, filters plugin and then added the extra part within the trans string
   but it still outputs nothing.
 * Should the function code be referencing the ‘value’ somewhere?
 * If it helps, I’m also using the below function, so there may be conflict?
 * require_once(ABSPATH . ‘wp-content/plugins/contact-form-7-to-database-extension/
   CFDBPermittedFunctions.php’);
    function parse_form_money($value) { return floatval(
   preg_replace(‘([^0-9.])’, ”, $value)); } cfdb_register_function(‘parse_form_money’);
 * Hmmm…
 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/adding-values-return-0/#post-7720428)
 * There shouldn’t be a conflict. But you might want to add the convert-null-to-
   zero code into your functions so that you don’t have 2 functions.
 * I suggest pull all the “trans” clauses out, then add them back in one-by-one,
   checking what results you get each time.
 *  Thread Starter [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * (@fabbstar)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/adding-values-return-0/#post-7722132)
 * Hi Michael,
 * Thanks for that. I’ve already taken up a lot of your time, but I’ll show you 
   what I have in place which still returns nothing, as opposed to zero.
 * Function code:
 *     ```
       require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBPermittedFunctions.php');
       function parse_form_money($value) {
       return floatval(preg_replace('([^0-9.])', '', $value));
       }
       cfdb_register_function('parse_form_money');
       function zero_if_null($x) {
           return is_null($x) ? 0 : $x;
       }
       cfdb_register_function('zero_if_null');
       ```
   
 * Shortcode:
 * `[cfdb-value tfilter=”Customer=$user_login&&Status=Completed” trans=”Value=parse_form_money(
   Value)&&SumField(Value)&&Value=number_format(Value,2)&&Value=concat(£,Value)&&
   Value=zero_if_null(Value)” form=”FORM NAME” show=”Value”]`
 * Maybe I am being silly and have missed something?
 * Thanks again,
    S
    -  This reply was modified 9 years, 7 months ago by [Fabbstar](https://wordpress.org/support/users/fabbstar/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding Values, Return 0’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/contact-form-7-to-database-extension_ffffff.
   svg)
 * [Contact Form DB](https://wordpress.org/plugins/contact-form-7-to-database-extension/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7-to-database-extension/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/reviews/)

## Tags

 * [values](https://wordpress.org/support/topic-tag/values/)

 * 4 replies
 * 2 participants
 * Last reply from: [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/adding-values-return-0/#post-7722132)
 * Status: not resolved