frm_pre_create_entry

Back to Top
Knowledge BaseEntry Management → frm_pre_create_entry

This hook can be used to manipulate the values in an entry prior to it's creation.

Usage

add_filter('frm_pre_create_entry', 'adjust_my_field');

Parameters

  • $values (array)

Examples

Formidable Hook - Helpful

Import file from URL

Submitted by srwells — 7 years ago

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;
}
Formidable Hook - Helpful

Prepend a value

Submitted by  — 7 years ago

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
    $field_id = 25; // change 25 to to id of your field
    $current_value = $values['item_meta'][ $field_id ]; // 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'][ $field_id ] = 'ss-00' . $values['item_meta'][ $field_id ];
    }
  }
  return $values;
}
If you would like to add your own example, click here.

Have something to add?

Click here to provide feedback on this page.