Formidable Forms

Formidable Forms

  • Features
  • Pricing
  • Resources
    • Docs & Support
    • Blog
    • Community
  • Solutions
    • Web Applications
    • Calculators
    • Surveys
    • Directories
    • Payments
    • Contact forms
  • 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.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

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.

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)
         wp_mail($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

Using WordPress and want to get Formidable Forms for free?

Get Formidable Forms Lite Now

You do not have permission to view this form. Maybe you need to log in?

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
  • Free Online Form Builder

Top Features

  • Application Builder
  • Calculator Forms
  • Surveys & Polls
  • Quiz Maker
  • Form Templates
  • Application Templates
  • Directories
  • Donation Plugin

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • WP Tasty
  • Nutrifox

Copyright © 2023 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 See User Reviews