Formidable Forms

The Most Advanced WordPress Forms Plugin and Form Builder

  • Features
  • Pricing
  • Blog
  • Support
  • Login
  • Get Formidable Forms

frm_add_entry_meta

Last Updated: May 1, 2018

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Entry Management → frm_add_entry_meta
Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

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)

Parameters

  • $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.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!
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('admin@site.com', 'example@example.com'); //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;
}
  • Usage
  • Parameters
  • Examples
    • Save a due date
    • Send email after submitting comment
    • Add coupon codes
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms
Install Formidable Lite

Using WordPress and want to get Formidable Forms for free?

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.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact

Top Features

  • Front End Editor
  • Repeating Fields
  • Views from Entries
  • Calculator Forms
  • Conditional Logic
  • Visual Form Styler
  • Form Templates
  • User Submitted Posts
  • File Upload Forms
  • Spam Protection
  • Multi Page Forms
  • Surveys & Polls
  • Form Graphs & Charts
  • Save and Continue
  • Mobile Forms
  • Stripe Forms
  • PayPal Forms
  • WooCommerce Forms
  • MailChimp Forms
  • User Registration
  • Signature Forms
  • Bootstrap Forms
  • Quiz Maker
  • Zapier Forms
  • Salesforce Forms
  • HubSpot Forms
  • API Webhooks
  • Multilingual Forms
  • Directories

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • Blog

Copyright © 2021 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

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