How to get created_at in formidable form

By: Sina Pars | Asked: 12/26/2022
ForumsCategory: How-toHow to get created_at in formidable form
Sina Pars asked 2 years ago
Hi there,
i am use frm_after_create_entry action to send a copy entiries to another table
Start your code here
add_action('frm_after_create_entry', 'copy_into_my_table', 20, 2);
function copy_into_my_table($entry_id, $form_id){
  if($form_id == 4){ //change 4 to the form id of the form to copy
    global $wpdb;
    $values = array('col_name1' => $_POST['item_meta'][25],
'col_name2' => $_POST['item_meta'][26]),
'Created_at' => $_POST[created_at]),; //replace 25 and 26 with the field ids of the Formidable form. Change col_name to the column names in your table $wpdb->insert('table_name', $values); } }
now i need to get created_at time and insert to another table every everyting is ok but created at now working

How to do this ?
2 Answers
Rob LeVineRob LeVine answered 2 years ago
The POST variable is for information passed by/to the form, so it won't be there in this case.  To get it you can do the following:

$entry = FrmEntry::getOne($entry_id);
$createdAt = $entry->created_at;
Sina Pars answered 2 years ago

Thanks for response Rob i am add this variable for resolve problem:

Start your code here
$now_time = wp_date('Y-m-d G:i:s');
'createdate' => $now_time

and finally code:

Start your code here 
add_action('frm_after_create_entry', 'copy_into_my_table', 20, 2); function copy_into_my_table($entry_id, $form_id){ if($form_id == 4){ //change 4 to the form id of the form to copy global $wpdb; $now_time = wp_date('Y-m-d G:i:s'); $values = array('col_name1' => $_POST['item_meta'][25], 'col_name2' => $_POST['item_meta'][26]), 'Created_at' => $now_time; //replace 25 and 26 with the field ids of the Formidable form. Change col_name to the column names in your table $wpdb->insert('table_name', $values); } }

 

 

Rob LeVineRob LeVine replied 2 years ago

Your solution will give you the time when it hits that code, not when the entry was created, it will be a few milliseconds different (you will end up with the original entry with time X and your new entry with time [X + some small amount]). If that's what you want, that's fine, but my point is that what you're doing is not what you asked about.

Sina Pars replied 2 years ago

You mentioned a good point, it's absolutely correct, but for my project, the difference of a few milliseconds doesn't matter,
Considering that your code is also executed in the function, will this difference be a few milliseconds or not?

Rob LeVineRob LeVine replied 2 years ago

The code is executed in the function, but it's getting a value that was previously set. If you use my method, the crreated_at value will match exactly between the two entries.

Sina Pars replied 2 years ago

Thanks Rob,
The reason why I did not use your code was that the time was not saved according to the time zone I wanted

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right