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_pre_create_entry

Last Updated: April 27, 2018

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Entry Management → frm_pre_create_entry
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 can be used to manipulate the values in an entry prior to it’s creation.

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

Usage

add_filter('frm_pre_create_entry', 'adjust_my_field');
function adjust_my_field($values)

Parameters

  • $values (array)

Examples

Prepend a value

This example allows you to prepend a static message before the user's field entry. For example, if the user entered '1234' and you wanted the value to be saved as 'ss-001234', you could use the code below to accomplish this.

add_filter('frm_pre_create_entry', 'adjust_my_field');
function adjust_my_field($values){
  if ( $values['form_id'] == 5 ) { //change 5 to your form id
    $current_value = $values['item_meta'][25]; // change 25 to to id of your field
    if ( strpos( $current_value, 'ss-00' ) === false ) { // check if the value is already included
      $values['item_meta'][25] = 'ss-00' . $values['item_meta'][25];
    }
  }
  return $values;
}

Import file from URL

This can come in handy in a few different cases. First, when using the API, you can accept a file url, and import it onto your site. Second, if you would like to accept links to files that are already online, rather then requiring users to download and then upload an image.

This example uses two different fields: one for the file url, and one for the upload field. The value in the url field will be used to fill the upload field when possible.

add_filter('frm_pre_create_entry', 'frm_upload_from_url');
function frm_upload_from_url( $values ) {
  if ( $values['form_id'] == 5 ) { //change 5 to your form id
    $upload_field_id = 25; // replace 25 with the id of your upload field
    $url_field = 24; // replace 24 with the id of your url field
    $has_url = isset( $values['item_meta'][ $url_field ] ) && ! empty( $values['item_meta'][ $url_field ] );
    $has_upload = isset( $values['item_meta'][ $upload_field_id ] ) && ! empty( $values['item_meta'][ $upload_field_id ] );
    if ( $has_url && ! $has_upload ) {
      $_REQUEST['csv_files'] = 1;
      $field = FrmField::getOne( $upload_field_id );
      $values['item_meta'][ $upload_field_id ] = FrmProFileImport::import_attachment( $values['item_meta'][ $url_field ], $field );
    }
  }
  return $values;
}

Choose field for entry name

Since a name field will now be used in an entry name, you can use this code example to choose which field gets used for the entry name.

add_filter('frm_pre_create_entry', 'frm_choose_field_entry_name');
function frm_choose_field_entry_name( $values ) {
	$target_form_id = 781; // change 781 to your form ID
	if ( $target_form_id === (int) $values['form_id'] ) {
		$target_field_id = 4529; // change 4529 to the field that you want to use for the entry name.
		$values['item_name'] = $values['item_meta'][ $target_field_id ];
	}
	return $values;
}
  • Usage
  • Parameters
  • Examples
    • Prepend a value
    • Import file from URL
    • Choose field for entry name
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

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