Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_add_entry_meta

This hook allows you to make changes to a value saved to a field right before it is sent to the database.

Usage

add_filter('frm_add_entry_meta', 'custom_change_field_value');
function custom_change_field_value($new_values)

Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.

Parameter

  • $new_values (array)

Examples

Save a due date

Use this code if you have a date field in your form and you want calculate a due date dependent on the selected date. This example will save a due date (in a hidden field) that is five weekdays after the selected date. You must have a value entered in the hidden field for this code to be used.

add_filter('frm_add_entry_meta', 'change_due_date');
function change_due_date($new_values) {
   if($new_values['field_id'] == 6103 and !is_admin()) { // 776 is the Due Date field on the form - note that this field must have a value in it on form submit or this code will not work
		$daystoadd = '5 weekdays'; // 3 business days is our standard turnaround
	$new_values['meta_value'] = date( 'm/d/Y' , strtotime ( $daystoadd ));
   }
return $new_values;
}

 

Send email after submitting comment

If you'd like an email notification sent when a comment is made from the "view" entry page in the back-end, you'll need a bit of custom code for now. This can be used to respond to the user who submitted the entry, a notification to admins, or another group you'd like email notifications to go to.

add_filter('frm_add_entry_meta', 'custom_change_field_value');
function custom_change_field_value($new_values){
   if($new_values['field_id'] == 0){ //0 indicates this is a comment
       $subject = 'New comment'; //change email subject here
       $send_to = array('[email protected]', '[email protected]'); //set email addresses here
       $info = maybe_unserialize($new_values['meta_value']);
       $message = $info['comment'];
       foreach($send_to as $to)
         FrmNotification::send_notification_email($to, $subject, $message);
   }
   return $new_values;
}

 

Add coupon codes

If you would like users to enter a coupon code in a form and get a discount depending on the code they entered, use this code example. In order for this code to work, you will need to create a new form and add a single line text field for the discount amount. Submit an entry for a discount amount. The coupon code will go in the entry key box. Submit a new entry for each coupon code.

add_filter('frm_add_entry_meta', 'apply_my_coupon');
function apply_my_coupon($values){
  if($values['field_id'] == 25){ //change 25 to the ID of the price field
    $coupon_field = 26; //change 26 to the ID of the coupon code field
    $discount_field = 30; //Change 30 to the ID of the discount amount field in the other form
    if(isset($_POST['item_meta'][$coupon_field]) and !empty($_POST['item_meta'][$coupon_field])){
       global $wpdb;
       $discount = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM " . $wpdb->prefix ."frm_item_metas em LEFT JOIN " . $wpdb->prefix ."frm_items e ON (e.id=em.item_id) WHERE field_id=%d AND item_key = %s ", $discount_field, $_POST['item_meta'][$coupon_field])); //get the discount amount
       if($discount){
          $new_price = (float) $values['meta_value'] - (float) $discount; //calculate the discounted price
          $_POST['item_meta'][$values['field_id']] = $values['meta_value'] = $new_price;
       }
    }
  }
  return $values;
}
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms