Hi, how do I insert data from a form into another table in the database if there is a repeater field in that form?
The effect I want to get:
Form:
field1
repeater field2 field3
table entry:
field1 | field2 | field3
_________________
val1 | val2 | val3
My snippet, but he create more than one row in table:
add_action('frm_after_create_entry', 'copy_pz', 20, 2);
function copy_pz($entry_id, $form_id){
if($form_id == 98){
global $wpdb;
foreach( $_POST['item_meta'][910] as $k => $r ) {
if ( is_array( $r ) ) {
foreach ( $r as $i => $v ) {
$values = array('faktura' => $_POST['item_meta'][909], 'towar' => $v);
$wpdb->insert('mag_stan', $values);
}
}
}
}
}
My form:
I already managed: add_action('frm_after_create_entry', 'copy_pz', 20, 2);
function copy_pz($entry_id, $form_id)
{ if($form_id == 98){ global $wpdb; foreach( $_POST['item_meta'][910] as $k => $r ) { if ( is_array( $r ) ) { foreach ( $r as $i => $v ) { if($i==912){ $towar=$v; }if($i==913){ $ilosc=$v; }if($i==914){ $cena=$v; }if($i==915){ $wartosc=$v; }if($i==915){ $values = array('faktura' => $_POST['item_meta'][909], 'towar' => $towar, 'ilosc' => $ilosc, 'cena' => $cena, 'wartosc' => $wartosc); $wpdb->insert('mag_stan', $values);} } } } } }
Does this mean you have it working? If so, please mark this thread as resolved.
where to add this code.. and which line code id need to be replace?
Please login or Register to submit your answer